Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2167)

Side by Side Diff: webkit/media/crypto/decoders/ffmpeg_video_decoder.cc

Issue 10899021: Add CDM video decoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/limits.h"
8 #include "media/ffmpeg/ffmpeg_common.h"
9 #include "webkit/media/crypto/decoders/ffmpeg_util.h"
10 #include "webkit/media/crypto/decoders/ffmpeg_video_decoder.h"
11 #include "webkit/media/crypto/ppapi/content_decryption_module.h"
12
13 namespace webkit_media {
14
15 using cdm::VideoDecoderConfig;
16 using cdm::VideoFrame;
17
18 static int GetVideoBufferImpl(AVCodecContext* s, AVFrame* frame) {
19 FFmpegVideoDecoder* vd = static_cast<FFmpegVideoDecoder*>(s->opaque);
20 return vd->GetVideoBuffer(s, frame);
21 }
22
23 static void ReleaseVideoBufferImpl(AVCodecContext* s, AVFrame* frame) {
24 scoped_refptr<VideoFrame> video_frame;
25 video_frame.swap(reinterpret_cast<VideoFrame**>(&frame->opaque));
26
27 // The FFmpeg API expects us to zero the data pointers in
28 // this callback
29 memset(frame->data, 0, sizeof(frame->data));
30 frame->opaque = NULL;
31 }
32
33 FFmpegVideoDecoder::FFmpegVideoDecoder()
34 : codec_context_(NULL),
35 av_frame_(NULL) {
36 }
37
38 FFmpegVideoDecoder::~FFmpegVideoDecoder() {
39 }
40
41 bool FFmpegVideoDecoder::Initialize(const VideoDecoderConfig& config) {
42 return false;
43 }
44
45 bool FFmpegVideoDecoder::DecodeFrame(const VideoFrame& compressed_frame,
46 VideoFrame* decompressed_frame) {
47 return false;
48 }
49
50 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context,
51 AVFrame* frame) {
52 // Don't use |codec_context_| here! With threaded decoding,
53 // it will contain unsynchronized width/height/pix_fmt values,
54 // whereas |codec_context| contains the current threads's
55 // updated width/height/pix_fmt, which can change for adaptive
56 // content.
57 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt);
58 if (format == VideoFrame::INVALID)
59 return AVERROR(EINVAL);
60 DCHECK(format == VideoFrame::YV12 || format == VideoFrame::YV16);
61
62 gfx::Size size(codec_context->width, codec_context->height);
63 int ret;
64 if ((ret = av_image_check_size(size.width(), size.height(), 0, NULL)) < 0)
65 return ret;
66
67 gfx::Size natural_size;
68 if (codec_context->sample_aspect_ratio.num > 0) {
69 natural_size = GetNaturalSize(size,
70 codec_context->sample_aspect_ratio.num,
71 codec_context->sample_aspect_ratio.den);
72 } else {
73 natural_size = demuxer_stream_->video_decoder_config().natural_size();
74 }
75
76 if (!VideoFrame::IsValidConfig(format, size, natural_size))
77 return AVERROR(EINVAL);
78
79 scoped_refptr<VideoFrame> video_frame =
80 VideoFrame::CreateFrame(format, size, natural_size, kNoTimestamp());
81
82 for (int i = 0; i < 3; i++) {
83 frame->base[i] = video_frame->data(i);
84 frame->data[i] = video_frame->data(i);
85 frame->linesize[i] = video_frame->stride(i);
86 }
87
88 frame->opaque = NULL;
89 video_frame.swap(reinterpret_cast<VideoFrame**>(&frame->opaque));
90 frame->type = FF_BUFFER_TYPE_USER;
91 frame->pkt_pts = codec_context->pkt ? codec_context->pkt->pts :
92 AV_NOPTS_VALUE;
93 frame->width = codec_context->width;
94 frame->height = codec_context->height;
95 frame->format = codec_context->pix_fmt;
96
97 return 0;
98 }
99
100 // static
101 bool VideoFrame::IsValidConfig(VideoFrame::Format format,
102 const Size& data_size) {
103 return (format != VideoFrame::INVALID &&
104 data_size.width() > 0 && data_size.height() > 0 &&
105 data_size.width() <= limits::kMaxDimension &&
106 data_size.height() <= limits::kMaxDimension &&
107 data_size.width() * data_size.height() <= limits::kMaxCanvas &&
108 natural_size.width() > 0 && natural_size.height() > 0 &&
109 natural_size.width() <= limits::kMaxDimension &&
110 natural_size.height() <= limits::kMaxDimension &&
111 natural_size.width() * natural_size.height() <= limits::kMaxCanvas);
112 }
113
114 void FFmpegVideoDecoder::ReleaseFFmpegResources() {
115 if (codec_context_) {
116 av_free(codec_context_->extradata);
117 avcodec_close(codec_context_);
118 av_free(codec_context_);
119 codec_context_ = NULL;
120 }
121 if (av_frame_) {
122 av_free(av_frame_);
123 av_frame_ = NULL;
124 }
125 }
126
127 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698