Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_LIBVPX_VIDEO_DECODER_H_ |
| 6 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_LIBVPX_VIDEO_DECODER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "media/base/decryptor.h" | |
| 11 #include "media/base/demuxer_stream.h" | 10 #include "media/base/demuxer_stream.h" |
| 12 #include "media/base/video_decoder.h" | 11 #include "media/base/video_decoder.h" |
| 13 | 12 |
| 14 struct AVCodecContext; | 13 struct vpx_codec_ctx; |
| 15 struct AVFrame; | 14 struct vpx_image; |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 18 class MessageLoopProxy; | 17 class MessageLoopProxy; |
| 19 } | 18 } |
| 20 | 19 |
| 21 namespace media { | 20 namespace media { |
| 22 | 21 |
| 23 class DecoderBuffer; | 22 class MEDIA_EXPORT LibvpxVideoDecoder : public VideoDecoder { |
| 23 public: | |
| 24 // Callback to notify decryptor creation. | |
| 25 //typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB; | |
| 24 | 26 |
| 25 class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder { | 27 // Callback to request/cancel decryptor creation notification. |
| 26 public: | 28 // Calling this callback with a non-null callback registers decryptor creation |
| 27 FFmpegVideoDecoder(const scoped_refptr<base::MessageLoopProxy>& message_loop, | 29 // notification. When the decryptor is created, notification will be sent |
| 28 Decryptor* decryptor); | 30 // through the provided callback. |
| 31 // Calling this callback with a null callback cancels previously registered | |
| 32 // decryptor creation notification. Any previously provided callback will be | |
| 33 // fired immediately with NULL. | |
| 34 //typedef base::Callback<void(const DecryptorNotificationCB&)> | |
| 35 // RequestDecryptorNotificationCB; | |
|
xhwang
2012/12/10 01:41:11
you don't need these if this class doesn't use a D
Tom Finegan
2012/12/13 09:57:26
Done.
| |
| 36 | |
| 37 LibvpxVideoDecoder( | |
| 38 const scoped_refptr<base::MessageLoopProxy>& message_loop); | |
| 29 | 39 |
| 30 // VideoDecoder implementation. | 40 // VideoDecoder implementation. |
| 31 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, | 41 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, |
| 32 const PipelineStatusCB& status_cb, | 42 const PipelineStatusCB& status_cb, |
| 33 const StatisticsCB& statistics_cb) OVERRIDE; | 43 const StatisticsCB& statistics_cb) OVERRIDE; |
| 34 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 44 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| 35 virtual void Reset(const base::Closure& closure) OVERRIDE; | 45 virtual void Reset(const base::Closure& closure) OVERRIDE; |
| 36 virtual void Stop(const base::Closure& closure) OVERRIDE; | 46 virtual void Stop(const base::Closure& closure) OVERRIDE; |
| 37 | 47 |
| 38 // Callback called from within FFmpeg to allocate a buffer based on | |
| 39 // the dimensions of |codec_context|. See AVCodecContext.get_buffer | |
| 40 // documentation inside FFmpeg. | |
| 41 int GetVideoBuffer(AVCodecContext *codec_context, AVFrame* frame); | |
| 42 | |
| 43 protected: | 48 protected: |
| 44 virtual ~FFmpegVideoDecoder(); | 49 virtual ~LibvpxVideoDecoder(); |
| 45 | 50 |
| 46 private: | 51 private: |
| 47 enum DecoderState { | 52 enum DecoderState { |
| 48 kUninitialized, | 53 kUninitialized, |
| 49 kNormal, | 54 kNormal, |
| 50 kFlushCodec, | 55 kFlushCodec, |
| 51 kDecodeFinished | 56 kDecodeFinished |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 // Carries out the reading operation scheduled by Read(). | 59 // Handles (re-)initializing the decoder with a (new) config. |
| 60 // Returns true when initialization was successful. | |
| 61 bool ConfigureDecoder(); | |
| 62 | |
| 63 void CloseDecoder(); | |
| 64 | |
| 65 // Carries out the buffer reading operation scheduled by Read(). | |
| 55 void DoRead(const ReadCB& read_cb); | 66 void DoRead(const ReadCB& read_cb); |
| 56 | 67 |
| 57 // Reads from the demuxer stream. | |
| 58 void ReadFromDemuxerStream(); | 68 void ReadFromDemuxerStream(); |
| 59 | 69 |
| 60 // Carries out the buffer processing operation scheduled by | 70 // Carries out the buffer processing operation scheduled by |
| 61 // DecryptOrDecodeBuffer(). | 71 // DecryptOrDecodeBuffer(). |
| 62 void DoDecryptOrDecodeBuffer(DemuxerStream::Status status, | 72 void DoDecryptOrDecodeBuffer(DemuxerStream::Status status, |
| 63 const scoped_refptr<DecoderBuffer>& buffer); | 73 const scoped_refptr<DecoderBuffer>& buffer); |
| 64 | 74 |
| 65 // Callback called by the decryptor to deliver decrypted data buffer and | |
| 66 // reporting decrypt status. This callback could be called synchronously or | |
| 67 // asynchronously. | |
| 68 void BufferDecrypted(Decryptor::Status decrypt_status, | |
| 69 const scoped_refptr<DecoderBuffer>& buffer); | |
| 70 | |
| 71 // Carries out the operation scheduled by BufferDecrypted(). | |
| 72 void DoBufferDecrypted(Decryptor::Status decrypt_status, | |
| 73 const scoped_refptr<DecoderBuffer>& buffer); | |
| 74 | |
| 75 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); | 75 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); |
| 76 bool Decode(const scoped_refptr<DecoderBuffer>& buffer, | 76 bool Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 77 scoped_refptr<VideoFrame>* video_frame); | 77 scoped_refptr<VideoFrame>* video_frame); |
| 78 | 78 |
| 79 // Handles (re-)initializing the decoder with a (new) config. | |
| 80 // Returns true if initialization was successful. | |
| 81 bool ConfigureDecoder(); | |
| 82 | |
| 83 // Releases resources associated with |codec_context_| and |av_frame_| | |
| 84 // and resets them to NULL. | |
| 85 void ReleaseFFmpegResources(); | |
| 86 | |
| 87 // Reset decoder and call |reset_cb_|. | 79 // Reset decoder and call |reset_cb_|. |
| 88 void DoReset(); | 80 void DoReset(); |
| 89 | 81 |
| 82 bool CopyVpxImageTo(const vpx_image* vpx_image, | |
| 83 scoped_refptr<VideoFrame>* video_frame); | |
| 84 | |
| 90 scoped_refptr<base::MessageLoopProxy> message_loop_; | 85 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 91 | 86 |
| 92 DecoderState state_; | 87 DecoderState state_; |
| 93 | 88 |
| 89 //PipelineStatusCB init_cb_; | |
|
xhwang
2012/12/10 01:41:11
do you need this?
Tom Finegan
2012/12/13 09:57:26
Done.
| |
| 94 StatisticsCB statistics_cb_; | 90 StatisticsCB statistics_cb_; |
| 95 | |
| 96 ReadCB read_cb_; | 91 ReadCB read_cb_; |
| 97 base::Closure reset_cb_; | 92 base::Closure reset_cb_; |
| 98 | 93 |
| 99 // FFmpeg structures owned by this object. | 94 int64 frame_num_; |
| 100 AVCodecContext* codec_context_; | 95 scoped_refptr<VideoFrame> video_frame_; |
| 101 AVFrame* av_frame_; | |
| 102 | 96 |
| 103 // Pointer to the demuxer stream that will feed us compressed buffers. | 97 // Pointer to the demuxer stream that will feed us compressed buffers. |
| 104 scoped_refptr<DemuxerStream> demuxer_stream_; | 98 scoped_refptr<DemuxerStream> demuxer_stream_; |
| 105 | 99 |
| 106 Decryptor* decryptor_; | 100 vpx_codec_ctx* vpx_codec_; |
| 107 | 101 |
| 108 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); | 102 DISALLOW_COPY_AND_ASSIGN(LibvpxVideoDecoder); |
| 109 }; | 103 }; |
| 110 | 104 |
| 111 } // namespace media | 105 } // namespace media |
| 112 | 106 |
| 113 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 107 #endif // MEDIA_FILTERS_LIBVPX_VIDEO_DECODER_H_ |
| OLD | NEW |