OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "base/memory/ref_counted.h" |
| 7 #include "media/base/buffers.h" |
| 8 #include "media/base/limits.h" |
| 9 #include "media/ffmpeg/ffmpeg_common.h" |
| 10 #include "webkit/media/crypto/decoders/ffmpeg_util.h" |
| 11 #include "webkit/media/crypto/decoders/ffmpeg_video_decoder.h" |
| 12 #include "webkit/media/crypto/ppapi/content_decryption_module.h" |
| 13 |
| 14 namespace webkit_media { |
| 15 |
| 16 using cdm::VideoDecoderConfig; |
| 17 using cdm::VideoFrame; |
| 18 |
| 19 static int GetVideoBufferImpl(AVCodecContext* s, AVFrame* frame) { |
| 20 FFmpegVideoDecoder* vd = static_cast<FFmpegVideoDecoder*>(s->opaque); |
| 21 return vd->GetVideoBuffer(s, frame); |
| 22 } |
| 23 |
| 24 static void ReleaseVideoBufferImpl(AVCodecContext* s, AVFrame* frame) { |
| 25 //scoped_refptr<VideoFrame> video_frame; |
| 26 //video_frame.swap(reinterpret_cast<VideoFrame**>(&frame->opaque)); |
| 27 |
| 28 // TODO(tomfinegan): Give the buffer back to the CDM wrapper, or free it? |
| 29 |
| 30 // The FFmpeg API expects us to zero the data pointers in |
| 31 // this callback |
| 32 memset(frame->data, 0, sizeof(frame->data)); |
| 33 frame->opaque = NULL; |
| 34 } |
| 35 |
| 36 FFmpegVideoDecoder::FFmpegVideoDecoder() |
| 37 : codec_context_(NULL), |
| 38 av_frame_(NULL) { |
| 39 } |
| 40 |
| 41 FFmpegVideoDecoder::~FFmpegVideoDecoder() { |
| 42 } |
| 43 |
| 44 bool FFmpegVideoDecoder::Initialize(const VideoDecoderConfig& config) { |
| 45 return false; |
| 46 } |
| 47 |
| 48 bool FFmpegVideoDecoder::DecodeFrame(const VideoFrame& compressed_frame, |
| 49 VideoFrame* decompressed_frame) { |
| 50 return false; |
| 51 } |
| 52 |
| 53 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, |
| 54 AVFrame* frame) { |
| 55 // Don't use |codec_context_| here! With threaded decoding, |
| 56 // it will contain unsynchronized width/height/pix_fmt values, |
| 57 // whereas |codec_context| contains the current threads's |
| 58 // updated width/height/pix_fmt, which can change for adaptive |
| 59 // content. |
| 60 VideoFrame::ColorFormat format = |
| 61 PixelFormatToVideoFormat(codec_context->pix_fmt); |
| 62 if (format == VideoFrame::kFormatInvalid) |
| 63 return AVERROR(EINVAL); |
| 64 DCHECK(format == VideoFrame::kFormatYv12 || |
| 65 format == VideoFrame::kFormatI420); |
| 66 |
| 67 VideoFrame::Size size(codec_context->width, codec_context->height); |
| 68 int ret; |
| 69 if ((ret = av_image_check_size(size.width, size.height, 0, NULL)) < 0) |
| 70 return ret; |
| 71 |
| 72 if (!IsValidConfig(format, size)) |
| 73 return AVERROR(EINVAL); |
| 74 |
| 75 VideoFrame* video_frame = CreateVideoFrame(format, size, |
| 76 media::kNoTimestamp()); |
| 77 |
| 78 for (int i = 0; i < 3; i++) { |
| 79 frame->base[i] = video_frame->data[i]; |
| 80 frame->data[i] = video_frame->data[i]; |
| 81 frame->linesize[i] = video_frame->strides[i]; |
| 82 } |
| 83 |
| 84 //frame->opaque = NULL; |
| 85 //video_frame.swap(reinterpret_cast<VideoFrame**>(&frame->opaque)); |
| 86 frame->opaque = reinterpret_cast<void*>(video_frame); |
| 87 frame->type = FF_BUFFER_TYPE_USER; |
| 88 frame->pkt_pts = codec_context->pkt ? codec_context->pkt->pts : |
| 89 AV_NOPTS_VALUE; |
| 90 frame->width = codec_context->width; |
| 91 frame->height = codec_context->height; |
| 92 frame->format = codec_context->pix_fmt; |
| 93 |
| 94 return 0; |
| 95 } |
| 96 |
| 97 // static |
| 98 bool FFmpegVideoDecoder::IsValidConfig(VideoFrame::ColorFormat format, |
| 99 const cdm::VideoFrame::Size& data_size) { |
| 100 return (format != VideoFrame::kFormatInvalid && |
| 101 data_size.width > 0 && data_size.height > 0 && |
| 102 data_size.width <= media::limits::kMaxDimension && |
| 103 data_size.height <= media::limits::kMaxDimension && |
| 104 data_size.width * data_size.height <= media::limits::kMaxCanvas); |
| 105 } |
| 106 |
| 107 // static |
| 108 cdm::VideoFrame* FFmpegVideoDecoder::CreateVideoFrame( |
| 109 cdm::VideoFrame::ColorFormat format, |
| 110 const cdm::VideoFrame::Size& size, |
| 111 const base::TimeDelta& timestamp) { |
| 112 // TODO(tomfinegan): Needs implementation. |
| 113 return NULL; |
| 114 } |
| 115 |
| 116 void FFmpegVideoDecoder::ReleaseFFmpegResources() { |
| 117 if (codec_context_) { |
| 118 av_free(codec_context_->extradata); |
| 119 avcodec_close(codec_context_); |
| 120 av_free(codec_context_); |
| 121 codec_context_ = NULL; |
| 122 } |
| 123 if (av_frame_) { |
| 124 av_free(av_frame_); |
| 125 av_frame_ = NULL; |
| 126 } |
| 127 } |
| 128 |
| 129 } // namespace webkit_media |
OLD | NEW |