Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: webrtc/modules/video_coding/generic_decoder.h

Issue 2764573002: Deliver video frames on Android, on the decode thread. (Closed)
Patch Set: Update comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ 12 #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
13 13
14 #include "webrtc/base/criticalsection.h" 14 #include <memory>
15
15 #include "webrtc/base/thread_checker.h" 16 #include "webrtc/base/thread_checker.h"
16 #include "webrtc/modules/include/module_common_types.h" 17 #include "webrtc/modules/include/module_common_types.h"
17 #include "webrtc/modules/video_coding/encoded_frame.h" 18 #include "webrtc/modules/video_coding/encoded_frame.h"
18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" 19 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
19 #include "webrtc/modules/video_coding/timestamp_map.h" 20 #include "webrtc/modules/video_coding/timestamp_map.h"
20 #include "webrtc/modules/video_coding/timing.h" 21 #include "webrtc/modules/video_coding/timing.h"
21 22
22 namespace webrtc { 23 namespace webrtc {
23 24
24 class VCMReceiveCallback; 25 class VCMReceiveCallback;
25 26
26 enum { kDecoderFrameMemoryLength = 10 }; 27 enum { kDecoderFrameMemoryLength = 10 };
27 28
28 struct VCMFrameInformation { 29 struct VCMFrameInformation {
29 int64_t renderTimeMs; 30 int64_t renderTimeMs;
30 int64_t decodeStartTimeMs; 31 int64_t decodeStartTimeMs;
31 void* userData; 32 void* userData;
32 VideoRotation rotation; 33 VideoRotation rotation;
33 }; 34 };
34 35
35 class VCMDecodedFrameCallback : public DecodedImageCallback { 36 class VCMDecodedFrameCallback : public DecodedImageCallback {
36 public: 37 public:
37 VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock); 38 VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
38 ~VCMDecodedFrameCallback() override; 39 ~VCMDecodedFrameCallback() override;
40
39 void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback); 41 void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
40 VCMReceiveCallback* UserReceiveCallback(); 42 VCMReceiveCallback* UserReceiveCallback();
41 43
42 int32_t Decoded(VideoFrame& decodedImage) override; 44 int32_t Decoded(VideoFrame& decodedImage) override;
43 int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override; 45 int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override;
44 void Decoded(VideoFrame& decodedImage, 46 void Decoded(VideoFrame& decodedImage,
45 rtc::Optional<int32_t> decode_time_ms, 47 rtc::Optional<int32_t> decode_time_ms,
46 rtc::Optional<uint8_t> qp) override; 48 rtc::Optional<uint8_t> qp) override;
47 int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override; 49 int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override;
48 int32_t ReceivedDecodedFrame(const uint64_t pictureId) override; 50 int32_t ReceivedDecodedFrame(const uint64_t pictureId) override;
49 51
50 uint64_t LastReceivedPictureID() const; 52 uint64_t LastReceivedPictureID() const;
51 void OnDecoderImplementationName(const char* implementation_name); 53 void OnDecoderImplementationName(const char* implementation_name);
52 54
53 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo); 55 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
54 int32_t Pop(uint32_t timestamp); 56 int32_t Pop(uint32_t timestamp);
55 57
56 private: 58 private:
57 rtc::ThreadChecker construction_thread_; 59 rtc::ThreadChecker construction_thread_;
58 // Protect |_timestampMap|. 60 rtc::ThreadChecker decoder_thread_;
59 Clock* const _clock; 61 Clock* const _clock;
60 // This callback must be set before the decoder thread starts running 62 // This callback must be set before the decoder thread starts running
61 // and must only be unset when external threads (e.g decoder thread) 63 // and must only be unset when external threads (e.g decoder thread)
62 // have been stopped. Due to that, the variable should regarded as const 64 // have been stopped. Due to that, the variable should regarded as const
63 // while there are more than one threads involved, it must be set 65 // while there are more than one threads involved, it must be set
64 // from the same thread, and therfore a lock is not required to access it. 66 // from the same thread, and therfore a lock is not required to access it.
65 VCMReceiveCallback* _receiveCallback = nullptr; 67 VCMReceiveCallback* _receiveCallback = nullptr;
66 VCMTiming* _timing; 68 VCMTiming* _timing ACCESS_ON(decoder_thread_);
67 rtc::CriticalSection lock_; 69 VCMTimestampMap _timestampMap ACCESS_ON(decoder_thread_);
68 VCMTimestampMap _timestampMap GUARDED_BY(lock_); 70 uint64_t _lastReceivedPictureID ACCESS_ON(decoder_thread_);
69 uint64_t _lastReceivedPictureID;
70 }; 71 };
71 72
72 class VCMGenericDecoder { 73 class VCMGenericDecoder {
73 friend class VCMCodecDataBase;
74
75 public: 74 public:
76 explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false); 75 explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false);
77 ~VCMGenericDecoder(); 76 ~VCMGenericDecoder();
78 77
79 /** 78 /**
80 * Initialize the decoder with the information from the VideoCodec 79 * Initialize the decoder with the information from the VideoCodec
81 */ 80 */
82 int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores); 81 int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores);
83 82
84 /** 83 /**
85 * Decode to a raw I420 frame, 84 * Decode to a raw I420 frame,
86 * 85 *
87 * inputVideoBuffer reference to encoded video frame 86 * inputVideoBuffer reference to encoded video frame
88 */ 87 */
89 int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); 88 int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs);
90 89
91 /** 90 /**
92 * Free the decoder memory
93 */
94 int32_t Release();
95
96 /**
97 * Set decode callback. Deregistering while decoding is illegal. 91 * Set decode callback. Deregistering while decoding is illegal.
98 */ 92 */
99 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); 93 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
100 94
101 bool External() const;
102 bool PrefersLateDecoding() const; 95 bool PrefersLateDecoding() const;
103 96
97 #if defined(WEBRTC_ANDROID)
98 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
99 void PollDecodedFrames();
100 #endif
101
102 bool IsSameDecoder(VideoDecoder* decoder) const {
103 return decoder_.get() == decoder;
104 }
105
104 private: 106 private:
105 VCMDecodedFrameCallback* _callback; 107 rtc::ThreadChecker decoder_thread_;
106 VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength]; 108 VCMDecodedFrameCallback* _callback ACCESS_ON(decoder_thread_);
107 uint32_t _nextFrameInfoIdx; 109 VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength] ACCESS_ON(
108 VideoDecoder* const _decoder; 110 decoder_thread_);
109 VideoCodecType _codecType; 111 uint32_t _nextFrameInfoIdx ACCESS_ON(decoder_thread_);
110 bool _isExternal; 112 std::unique_ptr<VideoDecoder> decoder_;
111 bool _keyFrameDecoded; 113 VideoCodecType _codecType ACCESS_ON(decoder_thread_);
114 const bool _isExternal;
112 }; 115 };
113 116
114 } // namespace webrtc 117 } // namespace webrtc
115 118
116 #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ 119 #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codec_database.cc ('k') | webrtc/modules/video_coding/generic_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698