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
3 // found in the LICENSE file.
5 #ifndef CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_
6 #define CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "media/base/audio_decoder_config.h"
16 #include "media/base/video_decoder_config.h"
18 namespace chromecast
{
20 class CodedFrameProvider
;
21 class DecoderBufferBase
;
22 class MediaMessageFifo
;
24 // AvStreamerProxy streams audio/video data from a coded frame provider
25 // to a media message fifo.
26 class AvStreamerProxy
{
31 // AvStreamerProxy gets frames and audio/video config
32 // from the |frame_provider| and feed them into the |fifo|.
33 void SetCodedFrameProvider(scoped_ptr
<CodedFrameProvider
> frame_provider
);
34 void SetMediaMessageFifo(scoped_ptr
<MediaMessageFifo
> fifo
);
36 // Starts fetching A/V buffers.
39 // Stops fetching A/V buffers and flush the pending buffers,
40 // invoking |flush_cb| when done.
41 void StopAndFlush(const base::Closure
& flush_cb
);
43 // 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 void OnFifoReadEvent();
48 void RequestBufferIfNeeded();
50 void OnNewBuffer(const scoped_refptr
<DecoderBufferBase
>& buffer
,
51 const ::media::AudioDecoderConfig
& audio_config
,
52 const ::media::VideoDecoderConfig
& video_config
);
54 void ProcessPendingData();
56 bool SendAudioDecoderConfig(const ::media::AudioDecoderConfig
& config
);
57 bool SendVideoDecoderConfig(const ::media::VideoDecoderConfig
& config
);
58 bool SendBuffer(const scoped_refptr
<DecoderBufferBase
>& buffer
);
60 void OnStopAndFlushDone();
62 base::ThreadChecker thread_checker_
;
64 scoped_ptr
<CodedFrameProvider
> frame_provider_
;
66 // Fifo used to convey A/V configs and buffers.
67 scoped_ptr
<MediaMessageFifo
> fifo_
;
72 // Indicates if there is a pending request to the coded frame provider.
75 // Pending config & buffer.
76 // |pending_av_data_| is set as long as one of the pending audio/video
77 // config or buffer is valid.
78 bool pending_av_data_
;
79 ::media::AudioDecoderConfig pending_audio_config_
;
80 ::media::VideoDecoderConfig pending_video_config_
;
81 scoped_refptr
<DecoderBufferBase
> pending_buffer_
;
83 // List of pending callbacks in StopAndFlush
84 std::list
<base::Closure
> pending_stop_flush_cb_list_
;
86 base::WeakPtr
<AvStreamerProxy
> weak_this_
;
87 base::WeakPtrFactory
<AvStreamerProxy
> weak_factory_
;
89 DISALLOW_COPY_AND_ASSIGN(AvStreamerProxy
);
93 } // namespace chromecast
95 #endif // CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_