Use UsbIds::GetVendorName to retrieve USB vendor name.
[chromium-blink-merge.git] / media / base / pipeline.cc
blobd1fae012cbff286c45aa0d218b2d06e12db7f296
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.
5 #include "media/base/pipeline.h"
7 #include <algorithm>
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/callback_helpers.h"
12 #include "base/command_line.h"
13 #include "base/compiler_specific.h"
14 #include "base/location.h"
15 #include "base/metrics/histogram.h"
16 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h"
20 #include "base/synchronization/condition_variable.h"
21 #include "media/base/media_log.h"
22 #include "media/base/media_switches.h"
23 #include "media/base/renderer.h"
24 #include "media/base/text_renderer.h"
25 #include "media/base/text_track_config.h"
26 #include "media/base/video_decoder_config.h"
28 using base::TimeDelta;
30 namespace media {
32 Pipeline::Pipeline(
33 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
34 MediaLog* media_log)
35 : task_runner_(task_runner),
36 media_log_(media_log),
37 running_(false),
38 did_loading_progress_(false),
39 volume_(1.0f),
40 playback_rate_(0.0f),
41 status_(PIPELINE_OK),
42 state_(kCreated),
43 renderer_ended_(false),
44 text_renderer_ended_(false),
45 demuxer_(NULL),
46 pending_cdm_context_(nullptr),
47 weak_factory_(this) {
48 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(kCreated));
49 media_log_->AddEvent(
50 media_log_->CreateEvent(MediaLogEvent::PIPELINE_CREATED));
53 Pipeline::~Pipeline() {
54 DCHECK(thread_checker_.CalledOnValidThread())
55 << "Pipeline must be destroyed on same thread that created it";
56 DCHECK(!running_) << "Stop() must complete before destroying object";
57 DCHECK(stop_cb_.is_null());
58 DCHECK(seek_cb_.is_null());
60 media_log_->AddEvent(
61 media_log_->CreateEvent(MediaLogEvent::PIPELINE_DESTROYED));
64 void Pipeline::Start(Demuxer* demuxer,
65 scoped_ptr<Renderer> renderer,
66 const base::Closure& ended_cb,
67 const PipelineStatusCB& error_cb,
68 const PipelineStatusCB& seek_cb,
69 const PipelineMetadataCB& metadata_cb,
70 const BufferingStateCB& buffering_state_cb,
71 const PaintCB& paint_cb,
72 const base::Closure& duration_change_cb,
73 const AddTextTrackCB& add_text_track_cb,
74 const base::Closure& waiting_for_decryption_key_cb) {
75 DCHECK(!ended_cb.is_null());
76 DCHECK(!error_cb.is_null());
77 DCHECK(!seek_cb.is_null());
78 DCHECK(!metadata_cb.is_null());
79 DCHECK(!buffering_state_cb.is_null());
80 DCHECK(!paint_cb.is_null());
82 base::AutoLock auto_lock(lock_);
83 CHECK(!running_) << "Media pipeline is already running";
84 running_ = true;
86 demuxer_ = demuxer;
87 renderer_ = renderer.Pass();
88 ended_cb_ = ended_cb;
89 error_cb_ = error_cb;
90 seek_cb_ = seek_cb;
91 metadata_cb_ = metadata_cb;
92 buffering_state_cb_ = buffering_state_cb;
93 paint_cb_ = paint_cb;
94 duration_change_cb_ = duration_change_cb;
95 add_text_track_cb_ = add_text_track_cb;
96 waiting_for_decryption_key_cb_ = waiting_for_decryption_key_cb;
98 task_runner_->PostTask(
99 FROM_HERE, base::Bind(&Pipeline::StartTask, weak_factory_.GetWeakPtr()));
102 void Pipeline::Stop(const base::Closure& stop_cb) {
103 DVLOG(2) << __FUNCTION__;
104 task_runner_->PostTask(
105 FROM_HERE,
106 base::Bind(&Pipeline::StopTask, weak_factory_.GetWeakPtr(), stop_cb));
109 void Pipeline::Seek(TimeDelta time, const PipelineStatusCB& seek_cb) {
110 base::AutoLock auto_lock(lock_);
111 if (!running_) {
112 DLOG(ERROR) << "Media pipeline isn't running. Ignoring Seek().";
113 return;
116 task_runner_->PostTask(
117 FROM_HERE,
118 base::Bind(
119 &Pipeline::SeekTask, weak_factory_.GetWeakPtr(), time, seek_cb));
122 bool Pipeline::IsRunning() const {
123 base::AutoLock auto_lock(lock_);
124 return running_;
127 float Pipeline::GetPlaybackRate() const {
128 base::AutoLock auto_lock(lock_);
129 return playback_rate_;
132 void Pipeline::SetPlaybackRate(float playback_rate) {
133 if (playback_rate < 0.0f)
134 return;
136 base::AutoLock auto_lock(lock_);
137 playback_rate_ = playback_rate;
138 if (running_) {
139 task_runner_->PostTask(FROM_HERE,
140 base::Bind(&Pipeline::PlaybackRateChangedTask,
141 weak_factory_.GetWeakPtr(),
142 playback_rate));
146 float Pipeline::GetVolume() const {
147 base::AutoLock auto_lock(lock_);
148 return volume_;
151 void Pipeline::SetVolume(float volume) {
152 if (volume < 0.0f || volume > 1.0f)
153 return;
155 base::AutoLock auto_lock(lock_);
156 volume_ = volume;
157 if (running_) {
158 task_runner_->PostTask(
159 FROM_HERE,
160 base::Bind(
161 &Pipeline::VolumeChangedTask, weak_factory_.GetWeakPtr(), volume));
165 TimeDelta Pipeline::GetMediaTime() const {
166 base::AutoLock auto_lock(lock_);
167 return renderer_ ? std::min(renderer_->GetMediaTime(), duration_)
168 : TimeDelta();
171 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const {
172 base::AutoLock auto_lock(lock_);
173 return buffered_time_ranges_;
176 TimeDelta Pipeline::GetMediaDuration() const {
177 base::AutoLock auto_lock(lock_);
178 return duration_;
181 bool Pipeline::DidLoadingProgress() {
182 base::AutoLock auto_lock(lock_);
183 bool ret = did_loading_progress_;
184 did_loading_progress_ = false;
185 return ret;
188 PipelineStatistics Pipeline::GetStatistics() const {
189 base::AutoLock auto_lock(lock_);
190 return statistics_;
193 void Pipeline::SetCdm(CdmContext* cdm_context,
194 const CdmAttachedCB& cdm_attached_cb) {
195 task_runner_->PostTask(
196 FROM_HERE, base::Bind(&Pipeline::SetCdmTask, weak_factory_.GetWeakPtr(),
197 cdm_context, cdm_attached_cb));
200 void Pipeline::SetErrorForTesting(PipelineStatus status) {
201 OnError(status);
204 bool Pipeline::HasWeakPtrsForTesting() const {
205 DCHECK(task_runner_->BelongsToCurrentThread());
206 return weak_factory_.HasWeakPtrs();
209 void Pipeline::SetState(State next_state) {
210 DVLOG(1) << GetStateString(state_) << " -> " << GetStateString(next_state);
212 state_ = next_state;
213 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state));
216 #define RETURN_STRING(state) case state: return #state;
218 const char* Pipeline::GetStateString(State state) {
219 switch (state) {
220 RETURN_STRING(kCreated);
221 RETURN_STRING(kInitDemuxer);
222 RETURN_STRING(kInitRenderer);
223 RETURN_STRING(kSeeking);
224 RETURN_STRING(kPlaying);
225 RETURN_STRING(kStopping);
226 RETURN_STRING(kStopped);
228 NOTREACHED();
229 return "INVALID";
232 #undef RETURN_STRING
234 Pipeline::State Pipeline::GetNextState() const {
235 DCHECK(task_runner_->BelongsToCurrentThread());
236 DCHECK(stop_cb_.is_null())
237 << "State transitions don't happen when stopping";
238 DCHECK_EQ(status_, PIPELINE_OK)
239 << "State transitions don't happen when there's an error: " << status_;
241 switch (state_) {
242 case kCreated:
243 return kInitDemuxer;
245 case kInitDemuxer:
246 return kInitRenderer;
248 case kInitRenderer:
249 case kSeeking:
250 return kPlaying;
252 case kPlaying:
253 case kStopping:
254 case kStopped:
255 break;
257 NOTREACHED() << "State has no transition: " << state_;
258 return state_;
261 void Pipeline::OnDemuxerError(PipelineStatus error) {
262 task_runner_->PostTask(FROM_HERE,
263 base::Bind(&Pipeline::ErrorChangedTask,
264 weak_factory_.GetWeakPtr(),
265 error));
268 void Pipeline::AddTextStream(DemuxerStream* text_stream,
269 const TextTrackConfig& config) {
270 task_runner_->PostTask(FROM_HERE,
271 base::Bind(&Pipeline::AddTextStreamTask,
272 weak_factory_.GetWeakPtr(),
273 text_stream,
274 config));
277 void Pipeline::RemoveTextStream(DemuxerStream* text_stream) {
278 task_runner_->PostTask(FROM_HERE,
279 base::Bind(&Pipeline::RemoveTextStreamTask,
280 weak_factory_.GetWeakPtr(),
281 text_stream));
284 void Pipeline::OnError(PipelineStatus error) {
285 DCHECK(task_runner_->BelongsToCurrentThread());
286 DCHECK(IsRunning());
287 DCHECK_NE(PIPELINE_OK, error);
288 VLOG(1) << "Media pipeline error: " << error;
290 task_runner_->PostTask(FROM_HERE, base::Bind(
291 &Pipeline::ErrorChangedTask, weak_factory_.GetWeakPtr(), error));
294 void Pipeline::SetDuration(TimeDelta duration) {
295 DCHECK(IsRunning());
296 media_log_->AddEvent(
297 media_log_->CreateTimeEvent(
298 MediaLogEvent::DURATION_SET, "duration", duration));
299 UMA_HISTOGRAM_LONG_TIMES("Media.Duration", duration);
301 base::AutoLock auto_lock(lock_);
302 duration_ = duration;
303 if (!duration_change_cb_.is_null())
304 duration_change_cb_.Run();
307 void Pipeline::StateTransitionTask(PipelineStatus status) {
308 DCHECK(task_runner_->BelongsToCurrentThread());
310 // No-op any state transitions if we're stopping.
311 if (state_ == kStopping || state_ == kStopped)
312 return;
314 // Preserve existing abnormal status, otherwise update based on the result of
315 // the previous operation.
316 status_ = (status_ != PIPELINE_OK ? status_ : status);
318 if (status_ != PIPELINE_OK) {
319 ErrorChangedTask(status_);
320 return;
323 // Guard against accidentally clearing |pending_callbacks_| for states that
324 // use it as well as states that should not be using it.
325 DCHECK_EQ(pending_callbacks_.get() != NULL, state_ == kSeeking);
327 pending_callbacks_.reset();
329 PipelineStatusCB done_cb =
330 base::Bind(&Pipeline::StateTransitionTask, weak_factory_.GetWeakPtr());
332 // Switch states, performing any entrance actions for the new state as well.
333 SetState(GetNextState());
334 switch (state_) {
335 case kInitDemuxer:
336 return InitializeDemuxer(done_cb);
338 case kInitRenderer:
339 // When the state_ transfers to kInitRenderer, it means the demuxer has
340 // finished parsing the init info. It should call ReportMetadata in case
341 // meeting 'decode' error when passing media segment but WebMediaPlayer's
342 // ready_state_ is still ReadyStateHaveNothing. In that case, it will
343 // treat it as NetworkStateFormatError not NetworkStateDecodeError.
344 ReportMetadata();
345 start_timestamp_ = demuxer_->GetStartTime();
347 return InitializeRenderer(done_cb);
349 case kPlaying:
350 DCHECK(start_timestamp_ >= base::TimeDelta());
351 renderer_->StartPlayingFrom(start_timestamp_);
353 if (text_renderer_)
354 text_renderer_->StartPlaying();
356 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_OK);
358 PlaybackRateChangedTask(GetPlaybackRate());
359 VolumeChangedTask(GetVolume());
360 return;
362 case kStopping:
363 case kStopped:
364 case kCreated:
365 case kSeeking:
366 NOTREACHED() << "State has no transition: " << state_;
367 return;
371 // Note that the usage of base::Unretained() with the renderers is considered
372 // safe as they are owned by |pending_callbacks_| and share the same lifetime.
374 // That being said, deleting the renderers while keeping |pending_callbacks_|
375 // running on the media thread would result in crashes.
376 void Pipeline::DoSeek(TimeDelta seek_timestamp,
377 const PipelineStatusCB& done_cb) {
378 DCHECK(task_runner_->BelongsToCurrentThread());
379 DCHECK(!pending_callbacks_.get());
380 DCHECK_EQ(state_, kSeeking);
381 SerialRunner::Queue bound_fns;
383 // Pause.
384 if (text_renderer_) {
385 bound_fns.Push(base::Bind(
386 &TextRenderer::Pause, base::Unretained(text_renderer_.get())));
389 // Flush.
390 DCHECK(renderer_);
391 bound_fns.Push(
392 base::Bind(&Renderer::Flush, base::Unretained(renderer_.get())));
394 if (text_renderer_) {
395 bound_fns.Push(base::Bind(
396 &TextRenderer::Flush, base::Unretained(text_renderer_.get())));
399 // Seek demuxer.
400 bound_fns.Push(base::Bind(
401 &Demuxer::Seek, base::Unretained(demuxer_), seek_timestamp));
403 pending_callbacks_ = SerialRunner::Run(bound_fns, done_cb);
406 void Pipeline::DoStop(const PipelineStatusCB& done_cb) {
407 DVLOG(2) << __FUNCTION__;
408 DCHECK(task_runner_->BelongsToCurrentThread());
409 DCHECK(!pending_callbacks_.get());
411 // TODO(scherkus): Enforce that Renderer is only called on a single thread,
412 // even for accessing media time http://crbug.com/370634
413 scoped_ptr<Renderer> renderer;
415 base::AutoLock auto_lock(lock_);
416 renderer.swap(renderer_);
418 renderer.reset();
419 text_renderer_.reset();
421 if (demuxer_) {
422 demuxer_->Stop();
423 demuxer_ = NULL;
426 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK));
429 void Pipeline::OnStopCompleted(PipelineStatus status) {
430 DVLOG(2) << __FUNCTION__;
431 DCHECK(task_runner_->BelongsToCurrentThread());
432 DCHECK_EQ(state_, kStopping);
433 DCHECK(!renderer_);
434 DCHECK(!text_renderer_);
437 base::AutoLock auto_lock(lock_);
438 running_ = false;
441 SetState(kStopped);
442 demuxer_ = NULL;
444 // If we stop during initialization/seeking we want to run |seek_cb_|
445 // followed by |stop_cb_| so we don't leave outstanding callbacks around.
446 if (!seek_cb_.is_null()) {
447 base::ResetAndReturn(&seek_cb_).Run(status_);
448 error_cb_.Reset();
450 if (!stop_cb_.is_null()) {
451 error_cb_.Reset();
453 // Invalid all weak pointers so it's safe to destroy |this| on the render
454 // main thread.
455 weak_factory_.InvalidateWeakPtrs();
457 base::ResetAndReturn(&stop_cb_).Run();
459 // NOTE: pipeline may be deleted at this point in time as a result of
460 // executing |stop_cb_|.
461 return;
463 if (!error_cb_.is_null()) {
464 DCHECK_NE(status_, PIPELINE_OK);
465 base::ResetAndReturn(&error_cb_).Run(status_);
469 void Pipeline::AddBufferedTimeRange(TimeDelta start, TimeDelta end) {
470 DCHECK(IsRunning());
471 base::AutoLock auto_lock(lock_);
472 buffered_time_ranges_.Add(start, end);
473 did_loading_progress_ = true;
476 // Called from any thread.
477 void Pipeline::OnUpdateStatistics(const PipelineStatistics& stats) {
478 base::AutoLock auto_lock(lock_);
479 statistics_.audio_bytes_decoded += stats.audio_bytes_decoded;
480 statistics_.video_bytes_decoded += stats.video_bytes_decoded;
481 statistics_.video_frames_decoded += stats.video_frames_decoded;
482 statistics_.video_frames_dropped += stats.video_frames_dropped;
485 void Pipeline::StartTask() {
486 DCHECK(task_runner_->BelongsToCurrentThread());
488 CHECK_EQ(kCreated, state_)
489 << "Media pipeline cannot be started more than once";
491 text_renderer_ = CreateTextRenderer();
492 if (text_renderer_) {
493 text_renderer_->Initialize(
494 base::Bind(&Pipeline::OnTextRendererEnded, weak_factory_.GetWeakPtr()));
497 // Set CDM early to avoid unnecessary delay in Renderer::Initialize().
498 if (pending_cdm_context_) {
499 renderer_->SetCdm(pending_cdm_context_, base::Bind(&IgnoreCdmAttached));
500 pending_cdm_context_ = nullptr;
503 StateTransitionTask(PIPELINE_OK);
506 void Pipeline::StopTask(const base::Closure& stop_cb) {
507 DCHECK(task_runner_->BelongsToCurrentThread());
508 DCHECK(stop_cb_.is_null());
510 if (state_ == kStopped) {
511 // Invalid all weak pointers so it's safe to destroy |this| on the render
512 // main thread.
513 weak_factory_.InvalidateWeakPtrs();
515 // NOTE: pipeline may be deleted at this point in time as a result of
516 // executing |stop_cb|.
517 stop_cb.Run();
519 return;
522 stop_cb_ = stop_cb;
524 // We may already be stopping due to a runtime error.
525 if (state_ == kStopping)
526 return;
528 // Do not report statistics if the pipeline is not fully initialized.
529 if (state_ == kSeeking || state_ == kPlaying) {
530 PipelineStatistics stats = GetStatistics();
531 if (renderer_->HasVideo() && stats.video_frames_decoded > 0) {
532 UMA_HISTOGRAM_COUNTS("Media.DroppedFrameCount",
533 stats.video_frames_dropped);
537 SetState(kStopping);
538 pending_callbacks_.reset();
539 DoStop(base::Bind(&Pipeline::OnStopCompleted, weak_factory_.GetWeakPtr()));
542 void Pipeline::ErrorChangedTask(PipelineStatus error) {
543 DCHECK(task_runner_->BelongsToCurrentThread());
544 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!";
546 media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(error));
548 if (state_ == kStopping || state_ == kStopped)
549 return;
551 SetState(kStopping);
552 pending_callbacks_.reset();
553 status_ = error;
555 DoStop(base::Bind(&Pipeline::OnStopCompleted, weak_factory_.GetWeakPtr()));
558 void Pipeline::PlaybackRateChangedTask(float playback_rate) {
559 DCHECK(task_runner_->BelongsToCurrentThread());
561 // Playback rate changes are only carried out while playing.
562 if (state_ != kPlaying)
563 return;
565 renderer_->SetPlaybackRate(playback_rate);
568 void Pipeline::VolumeChangedTask(float volume) {
569 DCHECK(task_runner_->BelongsToCurrentThread());
571 // Volume changes are only carried out while playing.
572 if (state_ != kPlaying)
573 return;
575 renderer_->SetVolume(volume);
578 void Pipeline::SeekTask(TimeDelta time, const PipelineStatusCB& seek_cb) {
579 DCHECK(task_runner_->BelongsToCurrentThread());
580 DCHECK(stop_cb_.is_null());
582 // Suppress seeking if we're not fully started.
583 if (state_ != kPlaying) {
584 DCHECK(state_ == kStopping || state_ == kStopped)
585 << "Receive extra seek in unexpected state: " << state_;
587 // TODO(scherkus): should we run the callback? I'm tempted to say the API
588 // will only execute the first Seek() request.
589 DVLOG(1) << "Media pipeline has not started, ignoring seek to "
590 << time.InMicroseconds() << " (current state: " << state_ << ")";
591 return;
594 DCHECK(seek_cb_.is_null());
596 const base::TimeDelta seek_timestamp =
597 std::max(time, demuxer_->GetStartTime());
599 SetState(kSeeking);
600 seek_cb_ = seek_cb;
601 renderer_ended_ = false;
602 text_renderer_ended_ = false;
603 start_timestamp_ = seek_timestamp;
605 DoSeek(seek_timestamp, base::Bind(&Pipeline::StateTransitionTask,
606 weak_factory_.GetWeakPtr()));
609 void Pipeline::SetCdmTask(CdmContext* cdm_context,
610 const CdmAttachedCB& cdm_attached_cb) {
611 base::AutoLock auto_lock(lock_);
612 if (!renderer_) {
613 pending_cdm_context_ = cdm_context;
614 cdm_attached_cb.Run(true);
615 return;
618 renderer_->SetCdm(cdm_context, cdm_attached_cb);
621 void Pipeline::OnRendererEnded() {
622 DCHECK(task_runner_->BelongsToCurrentThread());
623 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED));
625 if (state_ != kPlaying)
626 return;
628 DCHECK(!renderer_ended_);
629 renderer_ended_ = true;
631 RunEndedCallbackIfNeeded();
634 void Pipeline::OnTextRendererEnded() {
635 DCHECK(task_runner_->BelongsToCurrentThread());
636 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::TEXT_ENDED));
638 if (state_ != kPlaying)
639 return;
641 DCHECK(!text_renderer_ended_);
642 text_renderer_ended_ = true;
644 RunEndedCallbackIfNeeded();
647 void Pipeline::RunEndedCallbackIfNeeded() {
648 DCHECK(task_runner_->BelongsToCurrentThread());
650 if (renderer_ && !renderer_ended_)
651 return;
653 if (text_renderer_ && text_renderer_->HasTracks() && !text_renderer_ended_)
654 return;
656 // Correct the duration against current time if it turns out that
657 // the initially reported duration is wrong
658 // TODO(sriram): There are cases where duration is correct and current time
659 // falls short of duration by a few milliseconds. This is a workaround
660 // till we find the actual fix and 250ms is chosen here as it is
661 // the max time between timeupdate events (http://crbug.com/438581).
662 TimeDelta media_time = renderer_->GetMediaTime();
663 if ((duration_ - media_time).InMilliseconds() > 250)
664 SetDuration(media_time);
666 DCHECK_EQ(status_, PIPELINE_OK);
667 ended_cb_.Run();
670 scoped_ptr<TextRenderer> Pipeline::CreateTextRenderer() {
671 DCHECK(task_runner_->BelongsToCurrentThread());
673 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
674 if (!cmd_line->HasSwitch(switches::kEnableInbandTextTracks))
675 return scoped_ptr<media::TextRenderer>();
677 return scoped_ptr<media::TextRenderer>(new media::TextRenderer(
678 task_runner_,
679 base::Bind(&Pipeline::OnAddTextTrack, weak_factory_.GetWeakPtr())));
682 void Pipeline::AddTextStreamTask(DemuxerStream* text_stream,
683 const TextTrackConfig& config) {
684 DCHECK(task_runner_->BelongsToCurrentThread());
685 // TODO(matthewjheaney): fix up text_ended_ when text stream
686 // is added (http://crbug.com/321446).
687 if (text_renderer_)
688 text_renderer_->AddTextStream(text_stream, config);
691 void Pipeline::RemoveTextStreamTask(DemuxerStream* text_stream) {
692 DCHECK(task_runner_->BelongsToCurrentThread());
693 if (text_renderer_)
694 text_renderer_->RemoveTextStream(text_stream);
697 void Pipeline::OnAddTextTrack(const TextTrackConfig& config,
698 const AddTextTrackDoneCB& done_cb) {
699 DCHECK(task_runner_->BelongsToCurrentThread());
700 add_text_track_cb_.Run(config, done_cb);
703 void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) {
704 DCHECK(task_runner_->BelongsToCurrentThread());
705 demuxer_->Initialize(this, done_cb, text_renderer_);
708 void Pipeline::InitializeRenderer(const PipelineStatusCB& done_cb) {
709 DCHECK(task_runner_->BelongsToCurrentThread());
711 if (!demuxer_->GetStream(DemuxerStream::AUDIO) &&
712 !demuxer_->GetStream(DemuxerStream::VIDEO)) {
714 base::AutoLock auto_lock(lock_);
715 renderer_.reset();
717 OnError(PIPELINE_ERROR_COULD_NOT_RENDER);
718 return;
721 base::WeakPtr<Pipeline> weak_this = weak_factory_.GetWeakPtr();
722 renderer_->Initialize(
723 demuxer_,
724 done_cb,
725 base::Bind(&Pipeline::OnUpdateStatistics, weak_this),
726 base::Bind(&Pipeline::BufferingStateChanged, weak_this),
727 base::ResetAndReturn(&paint_cb_),
728 base::Bind(&Pipeline::OnRendererEnded, weak_this),
729 base::Bind(&Pipeline::OnError, weak_this),
730 waiting_for_decryption_key_cb_);
733 void Pipeline::ReportMetadata() {
734 DCHECK(task_runner_->BelongsToCurrentThread());
735 PipelineMetadata metadata;
736 metadata.timeline_offset = demuxer_->GetTimelineOffset();
737 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
738 if (stream) {
739 metadata.has_video = true;
740 metadata.natural_size = stream->video_decoder_config().natural_size();
741 metadata.video_rotation = stream->video_rotation();
743 if (demuxer_->GetStream(DemuxerStream::AUDIO)) {
744 metadata.has_audio = true;
746 metadata_cb_.Run(metadata);
749 void Pipeline::BufferingStateChanged(BufferingState new_buffering_state) {
750 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") ";
751 DCHECK(task_runner_->BelongsToCurrentThread());
752 buffering_state_cb_.Run(new_buffering_state);
755 } // namespace media