| OLD | NEW |
| 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 <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "webrtc/modules/include/module_common_types.h" | 16 #include "webrtc/modules/include/module_common_types.h" |
| 17 #include "webrtc/modules/video_coding/encoded_frame.h" | 17 #include "webrtc/modules/video_coding/encoded_frame.h" |
| 18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 18 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 19 #include "webrtc/modules/video_coding/timestamp_map.h" | 19 #include "webrtc/modules/video_coding/timestamp_map.h" |
| 20 #include "webrtc/modules/video_coding/timing.h" | 20 #include "webrtc/modules/video_coding/timing.h" |
| 21 #include "webrtc/rtc_base/criticalsection.h" | |
| 22 #include "webrtc/rtc_base/thread_checker.h" | 21 #include "webrtc/rtc_base/thread_checker.h" |
| 23 | 22 |
| 24 namespace webrtc { | 23 namespace webrtc { |
| 25 | 24 |
| 26 class VCMReceiveCallback; | 25 class VCMReceiveCallback; |
| 27 | 26 |
| 28 enum { kDecoderFrameMemoryLength = 10 }; | 27 enum { kDecoderFrameMemoryLength = 10 }; |
| 29 | 28 |
| 30 struct VCMFrameInformation { | 29 struct VCMFrameInformation { |
| 31 int64_t renderTimeMs; | 30 int64_t renderTimeMs; |
| 32 int64_t decodeStartTimeMs; | 31 int64_t decodeStartTimeMs; |
| 33 void* userData; | 32 void* userData; |
| 34 VideoRotation rotation; | 33 VideoRotation rotation; |
| 35 VideoContentType content_type; | 34 VideoContentType content_type; |
| 36 EncodedImage::Timing timing; | 35 EncodedImage::Timing timing; |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 class VCMDecodedFrameCallback : public DecodedImageCallback { | 38 class VCMDecodedFrameCallback : public DecodedImageCallback { |
| 40 public: | 39 public: |
| 41 VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock); | 40 VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock); |
| 42 ~VCMDecodedFrameCallback() override; | 41 ~VCMDecodedFrameCallback() override; |
| 42 |
| 43 void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback); | 43 void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback); |
| 44 VCMReceiveCallback* UserReceiveCallback(); | 44 VCMReceiveCallback* UserReceiveCallback(); |
| 45 | 45 |
| 46 int32_t Decoded(VideoFrame& decodedImage) override; | 46 int32_t Decoded(VideoFrame& decodedImage) override; |
| 47 int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override; | 47 int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override; |
| 48 void Decoded(VideoFrame& decodedImage, | 48 void Decoded(VideoFrame& decodedImage, |
| 49 rtc::Optional<int32_t> decode_time_ms, | 49 rtc::Optional<int32_t> decode_time_ms, |
| 50 rtc::Optional<uint8_t> qp) override; | 50 rtc::Optional<uint8_t> qp) override; |
| 51 int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override; | 51 int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override; |
| 52 int32_t ReceivedDecodedFrame(const uint64_t pictureId) override; | 52 int32_t ReceivedDecodedFrame(const uint64_t pictureId) override; |
| 53 | 53 |
| 54 uint64_t LastReceivedPictureID() const; | 54 uint64_t LastReceivedPictureID() const; |
| 55 void OnDecoderImplementationName(const char* implementation_name); | 55 void OnDecoderImplementationName(const char* implementation_name); |
| 56 | 56 |
| 57 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo); | 57 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo); |
| 58 int32_t Pop(uint32_t timestamp); | 58 int32_t Pop(uint32_t timestamp); |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 rtc::ThreadChecker construction_thread_; | 61 rtc::ThreadChecker construction_thread_; |
| 62 // Protect |_timestampMap|. | 62 rtc::ThreadChecker decoder_thread_; |
| 63 Clock* const _clock; | 63 Clock* const _clock; |
| 64 // This callback must be set before the decoder thread starts running | 64 // This callback must be set before the decoder thread starts running |
| 65 // and must only be unset when external threads (e.g decoder thread) | 65 // and must only be unset when external threads (e.g decoder thread) |
| 66 // have been stopped. Due to that, the variable should regarded as const | 66 // have been stopped. Due to that, the variable should regarded as const |
| 67 // while there are more than one threads involved, it must be set | 67 // while there are more than one threads involved, it must be set |
| 68 // from the same thread, and therfore a lock is not required to access it. | 68 // from the same thread, and therfore a lock is not required to access it. |
| 69 VCMReceiveCallback* _receiveCallback = nullptr; | 69 VCMReceiveCallback* _receiveCallback = nullptr; |
| 70 VCMTiming* _timing; | 70 VCMTiming* _timing ACCESS_ON(decoder_thread_); |
| 71 rtc::CriticalSection lock_; | 71 VCMTimestampMap _timestampMap ACCESS_ON(decoder_thread_); |
| 72 VCMTimestampMap _timestampMap GUARDED_BY(lock_); | 72 uint64_t _lastReceivedPictureID ACCESS_ON(decoder_thread_); |
| 73 uint64_t _lastReceivedPictureID; | |
| 74 int64_t ntp_offset_; | 73 int64_t ntp_offset_; |
| 75 }; | 74 }; |
| 76 | 75 |
| 77 class VCMGenericDecoder { | 76 class VCMGenericDecoder { |
| 78 public: | 77 public: |
| 79 explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false); | 78 explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false); |
| 80 ~VCMGenericDecoder(); | 79 ~VCMGenericDecoder(); |
| 81 | 80 |
| 82 /** | 81 /** |
| 83 * Initialize the decoder with the information from the VideoCodec | 82 * Initialize the decoder with the information from the VideoCodec |
| 84 */ | 83 */ |
| 85 int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores); | 84 int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores); |
| 86 | 85 |
| 87 /** | 86 /** |
| 88 * Decode to a raw I420 frame, | 87 * Decode to a raw I420 frame, |
| 89 * | 88 * |
| 90 * inputVideoBuffer reference to encoded video frame | 89 * inputVideoBuffer reference to encoded video frame |
| 91 */ | 90 */ |
| 92 int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); | 91 int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); |
| 93 | 92 |
| 94 /** | 93 /** |
| 95 * Set decode callback. Deregistering while decoding is illegal. | 94 * Set decode callback. Deregistering while decoding is illegal. |
| 96 */ | 95 */ |
| 97 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); | 96 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); |
| 98 | 97 |
| 99 bool External() const; | |
| 100 bool PrefersLateDecoding() const; | 98 bool PrefersLateDecoding() const; |
| 101 bool IsSameDecoder(VideoDecoder* decoder) const { | 99 bool IsSameDecoder(VideoDecoder* decoder) const { |
| 102 return decoder_.get() == decoder; | 100 return decoder_.get() == decoder; |
| 103 } | 101 } |
| 104 | 102 |
| 103 #if defined(WEBRTC_ANDROID) |
| 104 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361 |
| 105 void PollDecodedFrames(); |
| 106 #endif |
| 107 |
| 105 private: | 108 private: |
| 106 VCMDecodedFrameCallback* _callback; | 109 rtc::ThreadChecker decoder_thread_; |
| 107 VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength]; | 110 VCMDecodedFrameCallback* _callback ACCESS_ON(decoder_thread_); |
| 108 uint32_t _nextFrameInfoIdx; | 111 VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength] ACCESS_ON( |
| 112 decoder_thread_); |
| 113 uint32_t _nextFrameInfoIdx ACCESS_ON(decoder_thread_); |
| 109 std::unique_ptr<VideoDecoder> decoder_; | 114 std::unique_ptr<VideoDecoder> decoder_; |
| 110 VideoCodecType _codecType; | 115 VideoCodecType _codecType ACCESS_ON(decoder_thread_); |
| 111 const bool _isExternal; | 116 const bool _isExternal; |
| 112 VideoContentType _last_keyframe_content_type; | 117 VideoContentType _last_keyframe_content_type; |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 } // namespace webrtc | 120 } // namespace webrtc |
| 116 | 121 |
| 117 #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ | 122 #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |
| OLD | NEW |