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 WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_VIDEO_DECODER_H_ | 5 #ifndef WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_VIDEO_DECODER_H_ |
6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_VIDEO_DECODER_H_ | 6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_VIDEO_DECODER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "webkit/media/crypto/ppapi/content_decryption_module.h" | 10 #include "webkit/media/crypto/ppapi/content_decryption_module.h" |
11 | 11 |
12 struct AVCodecContext; | 12 struct AVCodecContext; |
13 struct AVFrame; | 13 struct AVFrame; |
14 | 14 |
| 15 // TODO(tomfinegan): Move Libvpx VP8 support to a new source file. |
| 16 typedef struct vpx_codec_ctx vpx_codec_ctx_t; |
| 17 typedef struct vpx_image vpx_image_t; |
| 18 |
| 19 |
15 namespace webkit_media { | 20 namespace webkit_media { |
16 | 21 |
17 class FFmpegCdmVideoDecoder { | 22 class FFmpegCdmVideoDecoder { |
18 public: | 23 public: |
19 explicit FFmpegCdmVideoDecoder(cdm::Allocator* allocator); | 24 explicit FFmpegCdmVideoDecoder(cdm::Allocator* allocator); |
20 ~FFmpegCdmVideoDecoder(); | 25 ~FFmpegCdmVideoDecoder(); |
21 bool Initialize(const cdm::VideoDecoderConfig& config); | 26 bool Initialize(const cdm::VideoDecoderConfig& config); |
22 void Deinitialize(); | 27 void Deinitialize(); |
23 void Reset(); | 28 void Reset(); |
24 | 29 |
25 // Returns true when |format| and |data_size| specify a supported video | 30 // Returns true when |format| and |data_size| specify a supported video |
26 // output configuration. | 31 // output configuration. |
27 static bool IsValidOutputConfig(cdm::VideoFormat format, | 32 static bool IsValidOutputConfig(cdm::VideoFormat format, |
28 const cdm::Size& data_size); | 33 const cdm::Size& data_size); |
29 | 34 |
30 // Decodes |compressed_frame|. Stores output frame in |decoded_frame| and | 35 // Decodes |compressed_frame|. Stores output frame in |decoded_frame| and |
31 // returns |cdm::kSuccess| when an output frame is available. Returns | 36 // returns |cdm::kSuccess| when an output frame is available. Returns |
32 // |cdm::kNeedMoreData| when |compressed_frame| does not produce an output | 37 // |cdm::kNeedMoreData| when |compressed_frame| does not produce an output |
33 // frame. Returns |cdm::kDecodeError| when decoding fails. | 38 // frame. Returns |cdm::kDecodeError| when decoding fails. |
34 cdm::Status DecodeFrame(const uint8_t* compressed_frame, | 39 cdm::Status DecodeFrame(const uint8_t* compressed_frame, |
35 int32_t compressed_frame_size, | 40 int32_t compressed_frame_size, |
36 int64_t timestamp, | 41 int64_t timestamp, |
37 cdm::VideoFrame* decoded_frame); | 42 cdm::VideoFrame* decoded_frame); |
38 | 43 |
39 private: | 44 private: |
| 45 // |
| 46 bool AllocateYuvFrameBuffer(int width, int height, |
| 47 cdm::VideoFrame* cdm_video_frame); |
| 48 |
40 // Allocates storage, then copies video frame stored in |av_frame_| to | 49 // Allocates storage, then copies video frame stored in |av_frame_| to |
41 // |cdm_video_frame|. Returns true when allocation and copy succeed. | 50 // |cdm_video_frame|. Returns true when allocation and copy succeed. |
42 bool CopyAvFrameTo(cdm::VideoFrame* cdm_video_frame); | 51 bool CopyAvFrameTo(cdm::VideoFrame* cdm_video_frame); |
| 52 bool CopyVpxImageTo(cdm::VideoFrame* cdm_video_frame); |
43 | 53 |
44 void ReleaseFFmpegResources(); | 54 void ReleaseFFmpegResources(); |
45 | 55 |
| 56 bool InitializeFFmpeg(const cdm::VideoDecoderConfig& config); |
| 57 bool InitializeLibvpx(const cdm::VideoDecoderConfig& config); |
| 58 cdm::Status DecodeFrameFFmpeg(const uint8_t* compressed_frame, |
| 59 int32_t compressed_frame_size, |
| 60 int64_t timestamp, |
| 61 cdm::VideoFrame* decoded_frame); |
| 62 cdm::Status DecodeFrameLibvpx(const uint8_t* compressed_frame, |
| 63 int32_t compressed_frame_size, |
| 64 int64_t timestamp, |
| 65 cdm::VideoFrame* decoded_frame); |
| 66 |
46 // FFmpeg structures owned by this object. | 67 // FFmpeg structures owned by this object. |
47 AVCodecContext* codec_context_; | 68 AVCodecContext* codec_context_; |
48 AVFrame* av_frame_; | 69 AVFrame* av_frame_; |
49 | 70 |
50 bool is_initialized_; | 71 bool is_initialized_; |
51 | 72 |
52 cdm::Allocator* const allocator_; | 73 cdm::Allocator* const allocator_; |
53 | 74 |
| 75 // TODO(tomfinegan): Libvpx VP8 decoding support does not belong in this |
| 76 // class. |
| 77 vpx_codec_ctx_t* vpx_codec_; |
| 78 vpx_image_t* vpx_image_; |
| 79 |
54 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmVideoDecoder); | 80 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmVideoDecoder); |
55 }; | 81 }; |
56 | 82 |
57 } // namespace webkit_media | 83 } // namespace webkit_media |
58 | 84 |
59 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_VIDEO_DECODER_H_ | 85 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_VIDEO_DECODER_H_ |
OLD | NEW |