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

Side by Side Diff: media/video/ffmpeg_video_decode_engine.cc

Issue 7587012: Remove mock_ffmpeg and update media unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "media/video/ffmpeg_video_decode_engine.h" 5 #include "media/video/ffmpeg_video_decode_engine.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/task.h" 9 #include "base/task.h"
10 #include "media/base/buffers.h" 10 #include "media/base/buffers.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Create output buffer pool when direct rendering is not used. 113 // Create output buffer pool when direct rendering is not used.
114 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) { 114 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) {
115 scoped_refptr<VideoFrame> video_frame = 115 scoped_refptr<VideoFrame> video_frame =
116 VideoFrame::CreateFrame(VideoFrame::YV12, 116 VideoFrame::CreateFrame(VideoFrame::YV12,
117 config.width(), 117 config.width(),
118 config.height(), 118 config.height(),
119 kNoTimestamp, 119 kNoTimestamp,
120 kNoTimestamp); 120 kNoTimestamp);
121 frame_queue_available_.push_back(video_frame); 121 frame_queue_available_.push_back(video_frame);
122 } 122 }
123
123 codec_context_->thread_count = decode_threads; 124 codec_context_->thread_count = decode_threads;
124 if (codec && 125 if (codec &&
125 avcodec_open(codec_context_, codec) >= 0 && 126 avcodec_open(codec_context_, codec) >= 0 &&
126 av_frame_.get()) { 127 av_frame_.get()) {
127 info.success = true; 128 info.success = true;
128 } 129 }
129 event_handler_ = event_handler; 130 event_handler_ = event_handler;
130 event_handler_->OnInitializeComplete(info); 131 event_handler_->OnInitializeComplete(info);
131 } 132 }
132 133
133 void FFmpegVideoDecodeEngine::ConsumeVideoSample( 134 void FFmpegVideoDecodeEngine::ConsumeVideoSample(
134 scoped_refptr<Buffer> buffer) { 135 scoped_refptr<Buffer> buffer) {
136 static int i = -1;
137
138 if (i >= 0) {
scherkus (not reviewing) 2011/08/11 01:26:29 woah!?? what's all this doing
acolwell GONE FROM CHROMIUM 2011/08/11 23:54:40 Oops. This is how I was extracting data for test f
139 char filename[100];
140 sprintf(filename, "vp8-frame-%d", i++);
141 printf("%s\n", filename);
142 FILE* f = fopen(filename, "wb");
143 DCHECK(f);
144 fwrite(buffer->GetData(), buffer->GetDataSize(), 1, f);
145 fclose(f);
146 }
147
135 pending_input_buffers_--; 148 pending_input_buffers_--;
136 if (flush_pending_) { 149 if (flush_pending_) {
137 TryToFinishPendingFlush(); 150 TryToFinishPendingFlush();
138 } else { 151 } else {
139 // Otherwise try to decode this buffer. 152 // Otherwise try to decode this buffer.
140 DecodeFrame(buffer); 153 DecodeFrame(buffer);
141 } 154 }
142 } 155 }
143 156
144 void FFmpegVideoDecodeEngine::ProduceVideoFrame( 157 void FFmpegVideoDecodeEngine::ProduceVideoFrame(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 192
180 // This is for codecs not using get_buffer to initialize 193 // This is for codecs not using get_buffer to initialize
181 // |av_frame_->reordered_opaque| 194 // |av_frame_->reordered_opaque|
182 av_frame_->reordered_opaque = codec_context_->reordered_opaque; 195 av_frame_->reordered_opaque = codec_context_->reordered_opaque;
183 196
184 int frame_decoded = 0; 197 int frame_decoded = 0;
185 int result = avcodec_decode_video2(codec_context_, 198 int result = avcodec_decode_video2(codec_context_,
186 av_frame_.get(), 199 av_frame_.get(),
187 &frame_decoded, 200 &frame_decoded,
188 &packet); 201 &packet);
189
190 // Log the problem if we can't decode a video frame and exit early. 202 // Log the problem if we can't decode a video frame and exit early.
191 if (result < 0) { 203 if (result < 0) {
192 LOG(ERROR) << "Error decoding a video frame with timestamp: " 204 LOG(ERROR) << "Error decoding a video frame with timestamp: "
193 << buffer->GetTimestamp().InMicroseconds() << " us, duration: " 205 << buffer->GetTimestamp().InMicroseconds() << " us, duration: "
194 << buffer->GetDuration().InMicroseconds() << " us, packet size: " 206 << buffer->GetDuration().InMicroseconds() << " us, packet size: "
195 << buffer->GetDataSize() << " bytes"; 207 << buffer->GetDataSize() << " bytes";
196 event_handler_->OnError(); 208 event_handler_->OnError();
197 return; 209 return;
198 } 210 }
199 211
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 308
297 event_handler_->OnSeekComplete(); 309 event_handler_->OnSeekComplete();
298 } 310 }
299 311
300 void FFmpegVideoDecodeEngine::ReadInput() { 312 void FFmpegVideoDecodeEngine::ReadInput() {
301 DCHECK_EQ(output_eos_reached_, false); 313 DCHECK_EQ(output_eos_reached_, false);
302 pending_input_buffers_++; 314 pending_input_buffers_++;
303 event_handler_->ProduceVideoSample(NULL); 315 event_handler_->ProduceVideoSample(NULL);
304 } 316 }
305 317
306 VideoFrame::Format FFmpegVideoDecodeEngine::GetSurfaceFormat() const {
307 // J (Motion JPEG) versions of YUV are full range 0..255.
308 // Regular (MPEG) YUV is 16..240.
309 // For now we will ignore the distinction and treat them the same.
310 switch (codec_context_->pix_fmt) {
311 case PIX_FMT_YUV420P:
312 case PIX_FMT_YUVJ420P:
313 return VideoFrame::YV12;
314 case PIX_FMT_YUV422P:
315 case PIX_FMT_YUVJ422P:
316 return VideoFrame::YV16;
317 default:
318 // TODO(scherkus): More formats here?
319 break;
320 }
321 return VideoFrame::INVALID;
322 }
323
324 } // namespace media 318 } // namespace media
325 319
326 // Disable refcounting for this object because this object only lives 320 // Disable refcounting for this object because this object only lives
327 // on the video decoder thread and there's no need to refcount it. 321 // on the video decoder thread and there's no need to refcount it.
328 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FFmpegVideoDecodeEngine); 322 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FFmpegVideoDecodeEngine);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698