OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "media/base/pipeline_status.h" |
| 13 #include "media/base/video_decoder.h" |
| 14 #include "third_party/webrtc/modules/video_coding/codecs/interface/video_codec_i
nterface.h" |
| 15 |
| 16 namespace base { |
| 17 class MessageLoopProxy; |
| 18 }; |
| 19 |
| 20 namespace content { |
| 21 |
| 22 class RTCDemuxerStream; |
| 23 |
| 24 // This class uses hardware accelerated video decoder to decode video for |
| 25 // WebRTC. The message loop passed to the constructor should be the same one for |
| 26 // GpuVideoDecoder. webrtc::VideoDecoder methods likes InitDecode() or Decode() |
| 27 // are called by a different thread and should trampoline to |
| 28 // |decoder_message_loop_|. Decode() is non-blocking and WebRTC calls it to |
| 29 // queue the encoded image buffers. Decoded frames are delivered to decode |
| 30 // complete callback by |decoder_message_loop_|. |
| 31 class CONTENT_EXPORT RTCVideoDecoder |
| 32 : NON_EXPORTED_BASE(public webrtc::VideoDecoder) { |
| 33 public: |
| 34 RTCVideoDecoder( |
| 35 media::VideoDecoder* video_decoder, |
| 36 const scoped_refptr<base::MessageLoopProxy>& message_loop); |
| 37 virtual ~RTCVideoDecoder(); |
| 38 |
| 39 // webrtc::VideoDecoder implementation. |
| 40 virtual int32_t InitDecode( |
| 41 const webrtc::VideoCodec* codecSettings, |
| 42 int32_t numberOfCores) OVERRIDE; |
| 43 virtual int32_t Decode( |
| 44 const webrtc::EncodedImage& inputImage, |
| 45 bool missingFrames, |
| 46 const webrtc::RTPFragmentationHeader* fragmentation, |
| 47 const webrtc::CodecSpecificInfo* codecSpecificInfo = NULL, |
| 48 int64_t renderTimeMs = -1) OVERRIDE; |
| 49 virtual int32_t RegisterDecodeCompleteCallback( |
| 50 webrtc::DecodedImageCallback* callback) OVERRIDE; |
| 51 virtual int32_t Release() OVERRIDE; |
| 52 virtual int32_t Reset() OVERRIDE; |
| 53 |
| 54 private: |
| 55 void InitWeakPtr(); |
| 56 void OnUpdateStatistics(const media::PipelineStatistics& stats); |
| 57 void OnUpdatePipelineStatus(const media::PipelineStatus status); |
| 58 void ReleaseComplete(); |
| 59 void ResetComplete(); |
| 60 void FrameReady( |
| 61 media::VideoDecoder::Status status, |
| 62 const scoped_refptr<media::VideoFrame>& frame); |
| 63 void RequestFrame(); |
| 64 |
| 65 enum State { |
| 66 kUninitialized, |
| 67 kInitialized, |
| 68 kDecoding, |
| 69 }; |
| 70 |
| 71 // Underlying hardware accelerated video decoder. |
| 72 scoped_ptr<media::VideoDecoder> video_decoder_; |
| 73 |
| 74 // The message loop to run callbacks. This should be the same as the main |
| 75 // message loop in GpuVideoDecoder. |
| 76 scoped_refptr<base::MessageLoopProxy> decoder_message_loop_; |
| 77 |
| 78 webrtc::DecodedImageCallback* decode_complete_callback_; |
| 79 media::PipelineStatus pipeline_status_; |
| 80 |
| 81 // Used to wait GpuVideoDecoder calls to complete. InitDecode(), Release(), |
| 82 // and Reset() are blocking calls. |
| 83 base::WaitableEvent decoder_waiter_; |
| 84 |
| 85 // Video buffer stream. |
| 86 scoped_ptr<RTCDemuxerStream> stream_; |
| 87 |
| 88 // The size of the video frames. |
| 89 gfx::Size size_; |
| 90 |
| 91 // The state of RTCVideoDecoder. |
| 92 State state_; |
| 93 |
| 94 base::WeakPtrFactory<RTCVideoDecoder> weak_factory_; |
| 95 base::WeakPtr<RTCVideoDecoder> weak_this_; |
| 96 base::WeakPtr<RTCDemuxerStream> weak_stream_; |
| 97 |
| 98 // Indicate a decoding error has occurred. This is read by WebRTC |
| 99 // DecodingThread and set by decoder_message_loop_. |
| 100 volatile bool decoding_error_occurred_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(RTCVideoDecoder); |
| 103 }; |
| 104 |
| 105 } // namespace content |
| 106 |
| 107 #endif // CONTENT_RENDERER_MEDIA_RTC_VIDEO_DECODER_H_ |
OLD | NEW |