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"
19 #include "media/cast/net/cast_transport_sender.h"
28 // The following callbacks are used to deliver decoded audio/video frame data,
29 // the frame's corresponding play-out time, and a continuity flag.
30 // |is_continuous| will be false to indicate the loss of data due to a loss of
31 // frames (or decoding errors). This allows the client to take steps to smooth
32 // discontinuities for playback. Note: A NULL pointer can be returned when data
33 // is not available (e.g., bad/missing packet).
34 typedef base::Callback
<void(scoped_ptr
<AudioBus
> audio_bus
,
35 const base::TimeTicks
& playout_time
,
36 bool is_continuous
)> AudioFrameDecodedCallback
;
37 // TODO(miu): |video_frame| includes a timestamp, so use that instead.
38 typedef base::Callback
<void(const scoped_refptr
<media::VideoFrame
>& video_frame
,
39 const base::TimeTicks
& playout_time
,
40 bool is_continuous
)> VideoFrameDecodedCallback
;
42 // The following callback delivers encoded frame data and metadata. The client
43 // should examine the |frame_id| field to determine whether any frames have been
44 // dropped (i.e., frame_id should be incrementing by one each time). Note: A
45 // NULL pointer can be returned on error.
46 typedef base::Callback
<void(scoped_ptr
<EncodedFrame
>)>
47 ReceiveEncodedFrameCallback
;
51 static scoped_ptr
<CastReceiver
> Create(
52 scoped_refptr
<CastEnvironment
> cast_environment
,
53 const FrameReceiverConfig
& audio_config
,
54 const FrameReceiverConfig
& video_config
,
55 CastTransportSender
* const transport
);
57 // All received RTP and RTCP packets for the call should be sent to this
58 // PacketReceiver. Can be called from any thread.
59 virtual void ReceivePacket(scoped_ptr
<Packet
> packet
) = 0;
61 // Polling interface to get audio and video frames from the CastReceiver. The
62 // the RequestDecodedXXXXXFrame() methods utilize internal software-based
63 // decoding, while the RequestEncodedXXXXXFrame() methods provides
64 // still-encoded frames for use with external/hardware decoders.
66 // In all cases, the given |callback| is guaranteed to be run at some point in
67 // the future, except for those requests still enqueued at destruction time.
69 // These methods should all be called on the CastEnvironment's MAIN thread.
70 virtual void RequestDecodedAudioFrame(
71 const AudioFrameDecodedCallback
& callback
) = 0;
72 virtual void RequestEncodedAudioFrame(
73 const ReceiveEncodedFrameCallback
& callback
) = 0;
74 virtual void RequestDecodedVideoFrame(
75 const VideoFrameDecodedCallback
& callback
) = 0;
76 virtual void RequestEncodedVideoFrame(
77 const ReceiveEncodedFrameCallback
& callback
) = 0;
79 virtual ~CastReceiver() {}
85 #endif // MEDIA_CAST_CAST_RECEIVER_H_