Index: chromecast/media/cma/ipc_streamer/coded_frame_provider_host.cc |
diff --git a/chromecast/media/cma/ipc_streamer/coded_frame_provider_host.cc b/chromecast/media/cma/ipc_streamer/coded_frame_provider_host.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c5d9ad507a47568151daf0baa1d1806c375ddebf |
--- /dev/null |
+++ b/chromecast/media/cma/ipc_streamer/coded_frame_provider_host.cc |
@@ -0,0 +1,90 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromecast/media/cma/ipc_streamer/coded_frame_provider_host.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback_helpers.h" |
+#include "chromecast/media/cma/base/decoder_buffer_base.h" |
+#include "chromecast/media/cma/ipc/media_message.h" |
+#include "chromecast/media/cma/ipc/media_message_fifo.h" |
+#include "chromecast/media/cma/ipc/media_message_type.h" |
+#include "chromecast/media/cma/ipc_streamer/audio_decoder_config_marshaller.h" |
+#include "chromecast/media/cma/ipc_streamer/decoder_buffer_base_marshaller.h" |
+#include "chromecast/media/cma/ipc_streamer/video_decoder_config_marshaller.h" |
+#include "media/base/buffers.h" |
+#include "media/base/decrypt_config.h" |
+ |
+namespace chromecast { |
+namespace media { |
+ |
+CodedFrameProviderHost::CodedFrameProviderHost( |
+ scoped_ptr<MediaMessageFifo> media_message_fifo) |
+ : fifo_(media_message_fifo.Pass()), |
+ weak_factory_(this), |
+ weak_this_(weak_factory_.GetWeakPtr()) { |
+ thread_checker_.DetachFromThread(); |
+} |
+ |
+CodedFrameProviderHost::~CodedFrameProviderHost() { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+} |
+ |
+void CodedFrameProviderHost::Read(const ReadCB& read_cb) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ // Cannot be called if there is already a pending read. |
+ DCHECK(read_cb_.is_null()); |
+ read_cb_ = read_cb; |
+ |
+ ReadMessages(); |
+} |
+ |
+void CodedFrameProviderHost::Flush(const base::Closure& flush_cb) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ audio_config_ = ::media::AudioDecoderConfig(); |
+ video_config_ = ::media::VideoDecoderConfig(); |
+ read_cb_.Reset(); |
+ fifo_->Flush(); |
+ flush_cb.Run(); |
+} |
+ |
+void CodedFrameProviderHost::OnFifoWriteEvent() { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ ReadMessages(); |
+} |
+ |
+base::Closure CodedFrameProviderHost::GetFifoWriteEventCb() { |
+ return base::Bind(&CodedFrameProviderHost::OnFifoWriteEvent, weak_this_); |
+} |
+ |
+void CodedFrameProviderHost::ReadMessages() { |
+ // Read messages until a frame is provided (i.e. not just the audio/video |
+ // configurations). |
+ while (!read_cb_.is_null()) { |
+ scoped_ptr<MediaMessage> msg(fifo_->Pop()); |
+ if (!msg) |
+ break; |
+ |
+ if (msg->type() == PaddingMediaMsg) { |
+ // Ignore the message. |
+ } else if (msg->type() == AudioConfigMediaMsg) { |
+ audio_config_ = AudioDecoderConfigMarshaller::Read(msg.get()); |
+ } else if (msg->type() == VideoConfigMediaMsg) { |
+ video_config_ = VideoDecoderConfigMarshaller::Read(msg.get()); |
+ } else if (msg->type() == FrameMediaMsg) { |
+ scoped_refptr<DecoderBufferBase> buffer = |
+ DecoderBufferBaseMarshaller::Read(msg.Pass()); |
+ base::ResetAndReturn(&read_cb_).Run( |
+ buffer, audio_config_, video_config_); |
+ audio_config_ = ::media::AudioDecoderConfig(); |
+ video_config_ = ::media::VideoDecoderConfig(); |
+ } else { |
+ LOG(FATAL) << "Unknown media message"; |
gunsch
2014/09/10 18:51:37
NOTREACHED
damienv1
2014/09/10 21:24:54
No. Entering this use case might mean the renderer
|
+ } |
+ } |
+} |
+ |
+} // namespace media |
+} // namespace chromecast |