Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / cast / cast_receiver.h
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.
4 //
5 // This is the main interface for the cast receiver. All configuration are done
6 // at creation.
7
8 #ifndef MEDIA_CAST_CAST_RECEIVER_H_
9 #define MEDIA_CAST_CAST_RECEIVER_H_
10
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/cast/cast_config.h"
17 #include "media/cast/cast_environment.h"
18
19 namespace media {
20 class VideoFrame;
21
22 namespace cast {
23
24 namespace transport {
25 class PacketSender;
26 }
27
28 // Callback in which the raw audio frame and play-out time will be returned
29 // once decoding is complete.
30 typedef base::Callback<void(scoped_ptr<PcmAudioFrame>, const base::TimeTicks&)>
31     AudioFrameDecodedCallback;
32
33 // Callback in which the encoded audio frame and play-out time will be returned.
34 typedef base::Callback<void(scoped_ptr<transport::EncodedAudioFrame>,
35                             const base::TimeTicks&)> AudioFrameEncodedCallback;
36
37 // Callback in which the raw frame and render time will be returned once
38 // decoding is complete.
39 typedef base::Callback<void(const scoped_refptr<media::VideoFrame>& video_frame,
40                             const base::TimeTicks&)> VideoFrameDecodedCallback;
41
42 // Callback in which the encoded video frame and render time will be returned.
43 typedef base::Callback<void(scoped_ptr<transport::EncodedVideoFrame>,
44                             const base::TimeTicks&)> VideoFrameEncodedCallback;
45
46 // This Class is thread safe.
47 class FrameReceiver : public base::RefCountedThreadSafe<FrameReceiver> {
48  public:
49   virtual void GetRawAudioFrame(int number_of_10ms_blocks,
50                                 int desired_frequency,
51                                 const AudioFrameDecodedCallback& callback) = 0;
52
53   virtual void GetCodedAudioFrame(
54       const AudioFrameEncodedCallback& callback) = 0;
55
56   virtual void GetRawVideoFrame(const VideoFrameDecodedCallback& callback) = 0;
57
58   virtual void GetEncodedVideoFrame(
59       const VideoFrameEncodedCallback& callback) = 0;
60
61  protected:
62   virtual ~FrameReceiver() {}
63
64  private:
65   friend class base::RefCountedThreadSafe<FrameReceiver>;
66 };
67
68 // This Class is thread safe.
69 class CastReceiver {
70  public:
71   static CastReceiver* CreateCastReceiver(
72       scoped_refptr<CastEnvironment> cast_environment,
73       const AudioReceiverConfig& audio_config,
74       const VideoReceiverConfig& video_config,
75       transport::PacketSender* const packet_sender);
76
77   // All received RTP and RTCP packets for the call should be sent to this
78   // PacketReceiver. Can be called from any function.
79   // TODO(hubbe): Replace with:
80   //   virtual void ReceivePacket(scoped_ptr<Packet> packet) = 0;
81   virtual transport::PacketReceiverCallback packet_receiver() = 0;
82
83   // Polling interface to get audio and video frames from the CastReceiver.
84   virtual scoped_refptr<FrameReceiver> frame_receiver() = 0;
85
86   virtual ~CastReceiver() {}
87 };
88
89 }  // namespace cast
90 }  // namespace media
91
92 #endif  // MEDIA_CAST_CAST_RECEIVER_H_