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 MEDIA_CAST_RECEIVER_CAST_RECEIVER_IMPL_H_
6 #define MEDIA_CAST_RECEIVER_CAST_RECEIVER_IMPL_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/cast/cast_config.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/cast_receiver.h"
13 #include "media/cast/net/pacing/paced_sender.h"
14 #include "media/cast/receiver/frame_receiver.h"
22 // This is a pure owner class that groups all required receiver-related objects
23 // together, such as the paced packet sender, audio/video RTP frame receivers,
24 // and software decoders (created on-demand).
25 class CastReceiverImpl
: public CastReceiver
{
27 CastReceiverImpl(scoped_refptr
<CastEnvironment
> cast_environment
,
28 const FrameReceiverConfig
& audio_config
,
29 const FrameReceiverConfig
& video_config
,
30 PacketSender
* const packet_sender
);
32 ~CastReceiverImpl() override
;
34 // CastReceiver implementation.
35 PacketReceiverCallback
packet_receiver() override
;
36 void RequestDecodedAudioFrame(
37 const AudioFrameDecodedCallback
& callback
) override
;
38 void RequestEncodedAudioFrame(
39 const ReceiveEncodedFrameCallback
& callback
) override
;
40 void RequestDecodedVideoFrame(
41 const VideoFrameDecodedCallback
& callback
) override
;
42 void RequestEncodedVideoFrame(
43 const ReceiveEncodedFrameCallback
& callback
) override
;
46 // Forwards |packet| to a specific RTP frame receiver, or drops it if SSRC
47 // does not map to one of the receivers.
48 void DispatchReceivedPacket(scoped_ptr
<Packet
> packet
);
50 // Feeds an EncodedFrame into |audio_decoder_|. RequestDecodedAudioFrame()
51 // uses this as a callback for RequestEncodedAudioFrame().
52 void DecodeEncodedAudioFrame(
53 const AudioFrameDecodedCallback
& callback
,
54 scoped_ptr
<EncodedFrame
> encoded_frame
);
56 // Feeds an EncodedFrame into |video_decoder_|. RequestDecodedVideoFrame()
57 // uses this as a callback for RequestEncodedVideoFrame().
58 void DecodeEncodedVideoFrame(
59 const VideoFrameDecodedCallback
& callback
,
60 scoped_ptr
<EncodedFrame
> encoded_frame
);
62 // Receives an AudioBus from |audio_decoder_|, logs the event, and passes the
63 // data on by running the given |callback|. This method is static to ensure
64 // it can be called after a CastReceiverImpl instance is destroyed.
65 // DecodeEncodedAudioFrame() uses this as a callback for
66 // AudioDecoder::DecodeFrame().
67 static void EmitDecodedAudioFrame(
68 const scoped_refptr
<CastEnvironment
>& cast_environment
,
69 const AudioFrameDecodedCallback
& callback
,
72 const base::TimeTicks
& playout_time
,
73 scoped_ptr
<AudioBus
> audio_bus
,
76 // Receives a VideoFrame from |video_decoder_|, logs the event, and passes the
77 // data on by running the given |callback|. This method is static to ensure
78 // it can be called after a CastReceiverImpl instance is destroyed.
79 // DecodeEncodedVideoFrame() uses this as a callback for
80 // VideoDecoder::DecodeFrame().
81 static void EmitDecodedVideoFrame(
82 const scoped_refptr
<CastEnvironment
>& cast_environment
,
83 const VideoFrameDecodedCallback
& callback
,
86 const base::TimeTicks
& playout_time
,
87 const scoped_refptr
<VideoFrame
>& video_frame
,
90 const scoped_refptr
<CastEnvironment
> cast_environment_
;
92 FrameReceiver audio_receiver_
;
93 FrameReceiver video_receiver_
;
95 // Used by DispatchReceivedPacket() to direct packets to the appropriate frame
97 const uint32 ssrc_of_audio_sender_
;
98 const uint32 ssrc_of_video_sender_
;
100 // Parameters for the decoders that are created on-demand. The values here
101 // might be nonsense if the client of CastReceiverImpl never intends to use
102 // the internal software-based decoders.
103 const int num_audio_channels_
;
104 const int audio_sampling_rate_
;
105 const Codec audio_codec_
;
106 const Codec video_codec_
;
108 // Created on-demand to decode frames from |audio_receiver_| into AudioBuses
110 scoped_ptr
<AudioDecoder
> audio_decoder_
;
112 // Created on-demand to decode frames from |video_receiver_| into VideoFrame
113 // images for playback.
114 scoped_ptr
<VideoDecoder
> video_decoder_
;
116 DISALLOW_COPY_AND_ASSIGN(CastReceiverImpl
);
122 #endif // MEDIA_CAST_RECEIVER_CAST_RECEIVER_IMPL_