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_
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "media/base/audio_decoder_config.h"
14 #include "media/base/video_decoder_config.h"
16 namespace chromecast
{
18 class CodedFrameProvider
;
19 class DecoderBufferBase
;
20 class MediaMessageFifo
;
22 // AvStreamerProxy streams audio/video data from a coded frame provider
23 // to a media message fifo.
24 class AvStreamerProxy
{
29 // AvStreamerProxy gets frames and audio/video config
30 // from the |frame_provider| and feed them into the |fifo|.
31 void SetCodedFrameProvider(scoped_ptr
<CodedFrameProvider
> frame_provider
);
32 void SetMediaMessageFifo(scoped_ptr
<MediaMessageFifo
> fifo
);
34 // Starts fetching A/V buffers.
37 // Stops fetching A/V buffers and flush the pending buffers,
38 // invoking |flush_cb| when done.
39 void StopAndFlush(const base::Closure
& flush_cb
);
41 // Event invoked when some data have been read from the fifo.
42 // This means some data can now possibly be written into the fifo.
43 void OnFifoReadEvent();
46 void RequestBufferIfNeeded();
48 void OnNewBuffer(const scoped_refptr
<DecoderBufferBase
>& buffer
,
49 const ::media::AudioDecoderConfig
& audio_config
,
50 const ::media::VideoDecoderConfig
& video_config
);
52 void ProcessPendingData();
54 bool SendAudioDecoderConfig(const ::media::AudioDecoderConfig
& config
);
55 bool SendVideoDecoderConfig(const ::media::VideoDecoderConfig
& config
);
56 bool SendBuffer(const scoped_refptr
<DecoderBufferBase
>& buffer
);
58 base::ThreadChecker thread_checker_
;
60 scoped_ptr
<CodedFrameProvider
> frame_provider_
;
62 // Fifo used to convey A/V configs and buffers.
63 scoped_ptr
<MediaMessageFifo
> fifo_
;
68 // Indicates if there is a pending request to the coded frame provider.
71 // Pending config & buffer.
72 // |pending_av_data_| is set as long as one of the pending audio/video
73 // config or buffer is valid.
74 bool pending_av_data_
;
75 ::media::AudioDecoderConfig pending_audio_config_
;
76 ::media::VideoDecoderConfig pending_video_config_
;
77 scoped_refptr
<DecoderBufferBase
> pending_buffer_
;
79 base::WeakPtr
<AvStreamerProxy
> weak_this_
;
80 base::WeakPtrFactory
<AvStreamerProxy
> weak_factory_
;
82 DISALLOW_COPY_AND_ASSIGN(AvStreamerProxy
);
86 } // namespace chromecast
88 #endif // CHROMECAST_MEDIA_CMA_IPC_STREAMER_AV_STREAMER_PROXY_H_