| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/media/cma/backend/video_decoder_default.h" | 5 #include "chromecast/media/cma/backend/video_decoder_default.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include "base/memory/ptr_util.h" |
| 8 | 8 #include "chromecast/media/cma/backend/media_sink_default.h" |
| 9 #include "base/bind.h" | |
| 10 #include "base/location.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/threading/thread_task_runner_handle.h" | |
| 13 #include "chromecast/public/media/cast_decoder_buffer.h" | |
| 14 | 9 |
| 15 namespace chromecast { | 10 namespace chromecast { |
| 16 namespace media { | 11 namespace media { |
| 17 | 12 |
| 18 VideoDecoderDefault::VideoDecoderDefault() | 13 VideoDecoderDefault::VideoDecoderDefault() {} |
| 19 : delegate_(nullptr), | |
| 20 last_push_pts_(std::numeric_limits<int64_t>::min()), | |
| 21 weak_factory_(this) {} | |
| 22 | 14 |
| 23 VideoDecoderDefault::~VideoDecoderDefault() {} | 15 VideoDecoderDefault::~VideoDecoderDefault() {} |
| 24 | 16 |
| 17 void VideoDecoderDefault::Start(base::TimeDelta start_pts) { |
| 18 DCHECK(!sink_); |
| 19 sink_ = base::MakeUnique<MediaSinkDefault>(delegate_, start_pts); |
| 20 } |
| 21 |
| 22 void VideoDecoderDefault::Stop() { |
| 23 DCHECK(sink_); |
| 24 sink_.reset(); |
| 25 } |
| 26 |
| 27 void VideoDecoderDefault::SetPlaybackRate(float rate) { |
| 28 DCHECK(sink_); |
| 29 sink_->SetPlaybackRate(rate); |
| 30 } |
| 31 |
| 32 base::TimeDelta VideoDecoderDefault::GetCurrentPts() { |
| 33 DCHECK(sink_); |
| 34 return sink_->GetCurrentPts(); |
| 35 } |
| 36 |
| 25 void VideoDecoderDefault::SetDelegate(Delegate* delegate) { | 37 void VideoDecoderDefault::SetDelegate(Delegate* delegate) { |
| 26 DCHECK(delegate); | 38 DCHECK(!sink_); |
| 27 delegate_ = delegate; | 39 delegate_ = delegate; |
| 28 } | 40 } |
| 29 | 41 |
| 30 MediaPipelineBackend::BufferStatus VideoDecoderDefault::PushBuffer( | 42 MediaPipelineBackend::BufferStatus VideoDecoderDefault::PushBuffer( |
| 31 CastDecoderBuffer* buffer) { | 43 CastDecoderBuffer* buffer) { |
| 32 DCHECK(delegate_); | 44 DCHECK(sink_); |
| 33 DCHECK(buffer); | 45 return sink_->PushBuffer(buffer); |
| 34 if (buffer->end_of_stream()) { | |
| 35 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 36 FROM_HERE, base::Bind(&VideoDecoderDefault::OnEndOfStream, | |
| 37 weak_factory_.GetWeakPtr())); | |
| 38 } else { | |
| 39 last_push_pts_ = buffer->timestamp(); | |
| 40 } | |
| 41 return MediaPipelineBackend::kBufferSuccess; | |
| 42 } | 46 } |
| 43 | 47 |
| 44 void VideoDecoderDefault::GetStatistics(Statistics* statistics) { | 48 void VideoDecoderDefault::GetStatistics(Statistics* statistics) { |
| 45 } | 49 } |
| 46 | 50 |
| 47 bool VideoDecoderDefault::SetConfig(const VideoConfig& config) { | 51 bool VideoDecoderDefault::SetConfig(const VideoConfig& config) { |
| 48 return true; | 52 return true; |
| 49 } | 53 } |
| 50 | 54 |
| 51 void VideoDecoderDefault::OnEndOfStream() { | |
| 52 delegate_->OnEndOfStream(); | |
| 53 } | |
| 54 | |
| 55 } // namespace media | 55 } // namespace media |
| 56 } // namespace chromecast | 56 } // namespace chromecast |
| OLD | NEW |