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

Side by Side Diff: media/webm/webm_stream_parser.cc

Issue 10134066: Replace StreamParserHost interface with callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make callbacks hold unretained references. Created 8 years, 7 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
« no previous file with comments | « media/webm/webm_stream_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "media/webm/webm_stream_parser.h" 5 #include "media/webm/webm_stream_parser.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/ffmpeg/ffmpeg_common.h" 9 #include "media/ffmpeg/ffmpeg_common.h"
10 #include "media/filters/ffmpeg_glue.h" 10 #include "media/filters/ffmpeg_glue.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 AVStreamToVideoDecoderConfig(stream, &video_config_); 174 AVStreamToVideoDecoderConfig(stream, &video_config_);
175 no_supported_streams = false; 175 no_supported_streams = false;
176 continue; 176 continue;
177 } 177 }
178 } 178 }
179 179
180 return !no_supported_streams; 180 return !no_supported_streams;
181 } 181 }
182 182
183 WebMStreamParser::WebMStreamParser() 183 WebMStreamParser::WebMStreamParser()
184 : state_(kWaitingForInit), 184 : state_(kWaitingForInit) {
185 host_(NULL) {
186 } 185 }
187 186
188 WebMStreamParser::~WebMStreamParser() {} 187 WebMStreamParser::~WebMStreamParser() {}
189 188
190 void WebMStreamParser::Init(const InitCB& init_cb, StreamParserHost* host) { 189 void WebMStreamParser::Init(const InitCB& init_cb,
190 const NewConfigCB& config_cb,
191 const NewBuffersCB& audio_cb,
192 const NewBuffersCB& video_cb) {
191 DCHECK_EQ(state_, kWaitingForInit); 193 DCHECK_EQ(state_, kWaitingForInit);
192 DCHECK(init_cb_.is_null()); 194 DCHECK(init_cb_.is_null());
193 DCHECK(!host_);
194 DCHECK(!init_cb.is_null()); 195 DCHECK(!init_cb.is_null());
195 DCHECK(host); 196 DCHECK(!config_cb.is_null());
197 DCHECK(!audio_cb.is_null() || !video_cb.is_null());
196 198
197 ChangeState(kParsingHeaders); 199 ChangeState(kParsingHeaders);
198 init_cb_ = init_cb; 200 init_cb_ = init_cb;
199 host_ = host; 201 config_cb_ = config_cb;
202 audio_cb_ = audio_cb;
203 video_cb_ = video_cb;
200 } 204 }
201 205
202 void WebMStreamParser::Flush() { 206 void WebMStreamParser::Flush() {
203 DCHECK_NE(state_, kWaitingForInit); 207 DCHECK_NE(state_, kWaitingForInit);
204 208
205 byte_queue_.Reset(); 209 byte_queue_.Reset();
206 210
207 if (state_ != kParsingClusters) 211 if (state_ != kParsingClusters)
208 return; 212 return;
209 213
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 double mult = info_parser.timecode_scale() / 1000.0; 325 double mult = info_parser.timecode_scale() / 1000.0;
322 int64 duration_in_us = info_parser.duration() * mult; 326 int64 duration_in_us = info_parser.duration() * mult;
323 duration = base::TimeDelta::FromMicroseconds(duration_in_us); 327 duration = base::TimeDelta::FromMicroseconds(duration_in_us);
324 } 328 }
325 329
326 FFmpegConfigHelper config_helper; 330 FFmpegConfigHelper config_helper;
327 331
328 if (!config_helper.Parse(data, bytes_parsed)) 332 if (!config_helper.Parse(data, bytes_parsed))
329 return -1; 333 return -1;
330 334
331 host_->OnNewConfigs(config_helper.audio_config(), 335 config_cb_.Run(config_helper.audio_config(),config_helper.video_config());
332 config_helper.video_config());
333 336
334 cluster_parser_.reset(new WebMClusterParser( 337 cluster_parser_.reset(new WebMClusterParser(
335 info_parser.timecode_scale(), 338 info_parser.timecode_scale(),
336 tracks_parser.audio_track_num(), 339 tracks_parser.audio_track_num(),
337 tracks_parser.audio_default_duration(), 340 tracks_parser.audio_default_duration(),
338 tracks_parser.video_track_num(), 341 tracks_parser.video_track_num(),
339 tracks_parser.video_default_duration(), 342 tracks_parser.video_default_duration(),
340 tracks_parser.video_encryption_key_id(), 343 tracks_parser.video_encryption_key_id(),
341 tracks_parser.video_encryption_key_id_size())); 344 tracks_parser.video_encryption_key_id_size()));
342 345
(...skipping 22 matching lines...) Expand all
365 } 368 }
366 // Skip the element. 369 // Skip the element.
367 return result + element_size; 370 return result + element_size;
368 } 371 }
369 372
370 int bytes_parsed = cluster_parser_->Parse(data, size); 373 int bytes_parsed = cluster_parser_->Parse(data, size);
371 374
372 if (bytes_parsed <= 0) 375 if (bytes_parsed <= 0)
373 return bytes_parsed; 376 return bytes_parsed;
374 377
375 const StreamParserHost::BufferQueue& audio_buffers = 378 const BufferQueue& audio_buffers = cluster_parser_->audio_buffers();
376 cluster_parser_->audio_buffers(); 379 const BufferQueue& video_buffers = cluster_parser_->video_buffers();
377 const StreamParserHost::BufferQueue& video_buffers =
378 cluster_parser_->video_buffers();
379 380
380 if (!audio_buffers.empty() && !host_->OnAudioBuffers(audio_buffers)) 381 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers))
381 return -1; 382 return -1;
382 383
383 if (!video_buffers.empty() && !host_->OnVideoBuffers(video_buffers)) 384 if (!video_buffers.empty() && !video_cb_.Run(video_buffers))
384 return -1; 385 return -1;
385 386
386 return bytes_parsed; 387 return bytes_parsed;
387 } 388 }
388 389
389 } // namespace media 390 } // namespace media
OLDNEW
« no previous file with comments | « media/webm/webm_stream_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698