1 // Copyright 2013 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 // This is the main interface for the cast receiver. All configuration are done
8 #ifndef MEDIA_CAST_CAST_RECEIVER_H_
9 #define MEDIA_CAST_CAST_RECEIVER_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/time/time.h"
16 #include "media/base/audio_bus.h"
17 #include "media/cast/cast_config.h"
18 #include "media/cast/cast_environment.h"
29 // The following callbacks are used to deliver decoded audio/video frame data,
30 // the frame's corresponding play-out time, and a continuity flag.
31 // |is_continuous| will be false to indicate the loss of data due to a loss of
32 // frames (or decoding errors). This allows the client to take steps to smooth
33 // discontinuities for playback. Note: A NULL pointer can be returned when data
34 // is not available (e.g., bad/missing packet).
35 typedef base::Callback
<void(scoped_ptr
<AudioBus
> audio_bus
,
36 const base::TimeTicks
& playout_time
,
37 bool is_continuous
)> AudioFrameDecodedCallback
;
38 // TODO(miu): |video_frame| includes a timestamp, so use that instead.
39 typedef base::Callback
<void(const scoped_refptr
<media::VideoFrame
>& video_frame
,
40 const base::TimeTicks
& playout_time
,
41 bool is_continuous
)> VideoFrameDecodedCallback
;
43 // The following callbacks deliver still-encoded audio/video frame data, along
44 // with the frame's corresponding play-out time. The client should examine the
45 // EncodedXXXFrame::frame_id field to determine whether any frames have been
46 // dropped (i.e., frame_id should be incrementing by one each time). Note: A
47 // NULL pointer can be returned on error.
48 typedef base::Callback
<void(scoped_ptr
<transport::EncodedAudioFrame
>,
49 const base::TimeTicks
&)> AudioFrameEncodedCallback
;
50 typedef base::Callback
<void(scoped_ptr
<transport::EncodedVideoFrame
>,
51 const base::TimeTicks
&)> VideoFrameEncodedCallback
;
53 // This Class is thread safe.
54 class FrameReceiver
: public base::RefCountedThreadSafe
<FrameReceiver
> {
56 virtual void GetRawAudioFrame(const AudioFrameDecodedCallback
& callback
) = 0;
58 virtual void GetCodedAudioFrame(
59 const AudioFrameEncodedCallback
& callback
) = 0;
61 virtual void GetRawVideoFrame(const VideoFrameDecodedCallback
& callback
) = 0;
63 virtual void GetEncodedVideoFrame(
64 const VideoFrameEncodedCallback
& callback
) = 0;
67 virtual ~FrameReceiver() {}
70 friend class base::RefCountedThreadSafe
<FrameReceiver
>;
73 // This Class is thread safe.
76 static scoped_ptr
<CastReceiver
> Create(
77 scoped_refptr
<CastEnvironment
> cast_environment
,
78 const AudioReceiverConfig
& audio_config
,
79 const VideoReceiverConfig
& video_config
,
80 transport::PacketSender
* const packet_sender
);
82 // All received RTP and RTCP packets for the call should be sent to this
83 // PacketReceiver. Can be called from any function.
84 // TODO(hubbe): Replace with:
85 // virtual void ReceivePacket(scoped_ptr<Packet> packet) = 0;
86 virtual transport::PacketReceiverCallback
packet_receiver() = 0;
88 // Polling interface to get audio and video frames from the CastReceiver.
89 virtual scoped_refptr
<FrameReceiver
> frame_receiver() = 0;
91 virtual ~CastReceiver() {}
97 #endif // MEDIA_CAST_CAST_RECEIVER_H_