| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_ | 5 #ifndef CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_ |
| 6 #define CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_ | 6 #define CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> |
| 9 | 10 |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "media/base/audio_decoder_config.h" | 15 #include "media/base/audio_decoder_config.h" |
| 16 #include "media/base/video_decoder_config.h" | 16 #include "media/base/video_decoder_config.h" |
| 17 | 17 |
| 18 namespace chromecast { | 18 namespace chromecast { |
| 19 namespace media { | 19 namespace media { |
| 20 class CodedFrameProvider; | 20 class CodedFrameProvider; |
| 21 class DecoderBufferBase; | 21 class DecoderBufferBase; |
| 22 class MediaMessageFifo; | 22 class MediaMessageFifo; |
| 23 | 23 |
| 24 // AvStreamerProxy streams audio/video data from a coded frame provider | 24 // AvStreamerProxy streams audio/video data from a coded frame provider |
| 25 // to a media message fifo. | 25 // to a media message fifo. |
| 26 class AvStreamerProxy { | 26 class AvStreamerProxy { |
| 27 public: | 27 public: |
| 28 AvStreamerProxy(); | 28 AvStreamerProxy(); |
| 29 ~AvStreamerProxy(); | 29 ~AvStreamerProxy(); |
| 30 | 30 |
| 31 // AvStreamerProxy gets frames and audio/video config | 31 // AvStreamerProxy gets frames and audio/video config |
| 32 // from the |frame_provider| and feed them into the |fifo|. | 32 // from the |frame_provider| and feed them into the |fifo|. |
| 33 void SetCodedFrameProvider(scoped_ptr<CodedFrameProvider> frame_provider); | 33 void SetCodedFrameProvider( |
| 34 void SetMediaMessageFifo(scoped_ptr<MediaMessageFifo> fifo); | 34 std::unique_ptr<CodedFrameProvider> frame_provider); |
| 35 void SetMediaMessageFifo(std::unique_ptr<MediaMessageFifo> fifo); |
| 35 | 36 |
| 36 // Starts fetching A/V buffers. | 37 // Starts fetching A/V buffers. |
| 37 void Start(); | 38 void Start(); |
| 38 | 39 |
| 39 // Stops fetching A/V buffers and flush the pending buffers, | 40 // Stops fetching A/V buffers and flush the pending buffers, |
| 40 // invoking |flush_cb| when done. | 41 // invoking |flush_cb| when done. |
| 41 void StopAndFlush(const base::Closure& flush_cb); | 42 void StopAndFlush(const base::Closure& flush_cb); |
| 42 | 43 |
| 43 // Event invoked when some data have been read from the fifo. | 44 // Event invoked when some data have been read from the fifo. |
| 44 // This means some data can now possibly be written into the fifo. | 45 // This means some data can now possibly be written into the fifo. |
| 45 void OnFifoReadEvent(); | 46 void OnFifoReadEvent(); |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 void RequestBufferIfNeeded(); | 49 void RequestBufferIfNeeded(); |
| 49 | 50 |
| 50 void OnNewBuffer(const scoped_refptr<DecoderBufferBase>& buffer, | 51 void OnNewBuffer(const scoped_refptr<DecoderBufferBase>& buffer, |
| 51 const ::media::AudioDecoderConfig& audio_config, | 52 const ::media::AudioDecoderConfig& audio_config, |
| 52 const ::media::VideoDecoderConfig& video_config); | 53 const ::media::VideoDecoderConfig& video_config); |
| 53 | 54 |
| 54 void ProcessPendingData(); | 55 void ProcessPendingData(); |
| 55 | 56 |
| 56 bool SendAudioDecoderConfig(const ::media::AudioDecoderConfig& config); | 57 bool SendAudioDecoderConfig(const ::media::AudioDecoderConfig& config); |
| 57 bool SendVideoDecoderConfig(const ::media::VideoDecoderConfig& config); | 58 bool SendVideoDecoderConfig(const ::media::VideoDecoderConfig& config); |
| 58 bool SendBuffer(const scoped_refptr<DecoderBufferBase>& buffer); | 59 bool SendBuffer(const scoped_refptr<DecoderBufferBase>& buffer); |
| 59 | 60 |
| 60 void OnStopAndFlushDone(); | 61 void OnStopAndFlushDone(); |
| 61 | 62 |
| 62 base::ThreadChecker thread_checker_; | 63 base::ThreadChecker thread_checker_; |
| 63 | 64 |
| 64 scoped_ptr<CodedFrameProvider> frame_provider_; | 65 std::unique_ptr<CodedFrameProvider> frame_provider_; |
| 65 | 66 |
| 66 // Fifo used to convey A/V configs and buffers. | 67 // Fifo used to convey A/V configs and buffers. |
| 67 scoped_ptr<MediaMessageFifo> fifo_; | 68 std::unique_ptr<MediaMessageFifo> fifo_; |
| 68 | 69 |
| 69 // State. | 70 // State. |
| 70 bool is_running_; | 71 bool is_running_; |
| 71 | 72 |
| 72 // Indicates if there is a pending request to the coded frame provider. | 73 // Indicates if there is a pending request to the coded frame provider. |
| 73 bool pending_read_; | 74 bool pending_read_; |
| 74 | 75 |
| 75 // Pending config & buffer. | 76 // Pending config & buffer. |
| 76 // |pending_av_data_| is set as long as one of the pending audio/video | 77 // |pending_av_data_| is set as long as one of the pending audio/video |
| 77 // config or buffer is valid. | 78 // config or buffer is valid. |
| 78 bool pending_av_data_; | 79 bool pending_av_data_; |
| 79 ::media::AudioDecoderConfig pending_audio_config_; | 80 ::media::AudioDecoderConfig pending_audio_config_; |
| 80 ::media::VideoDecoderConfig pending_video_config_; | 81 ::media::VideoDecoderConfig pending_video_config_; |
| 81 scoped_refptr<DecoderBufferBase> pending_buffer_; | 82 scoped_refptr<DecoderBufferBase> pending_buffer_; |
| 82 | 83 |
| 83 // List of pending callbacks in StopAndFlush | 84 // List of pending callbacks in StopAndFlush |
| 84 std::list<base::Closure> pending_stop_flush_cb_list_; | 85 std::list<base::Closure> pending_stop_flush_cb_list_; |
| 85 | 86 |
| 86 base::WeakPtr<AvStreamerProxy> weak_this_; | 87 base::WeakPtr<AvStreamerProxy> weak_this_; |
| 87 base::WeakPtrFactory<AvStreamerProxy> weak_factory_; | 88 base::WeakPtrFactory<AvStreamerProxy> weak_factory_; |
| 88 | 89 |
| 89 DISALLOW_COPY_AND_ASSIGN(AvStreamerProxy); | 90 DISALLOW_COPY_AND_ASSIGN(AvStreamerProxy); |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 } // namespace media | 93 } // namespace media |
| 93 } // namespace chromecast | 94 } // namespace chromecast |
| 94 | 95 |
| 95 #endif // CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_ | 96 #endif // CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_ |
| OLD | NEW |