summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/media/cast_receiver_session.h
blob: f41e24ba2eef072bd8c8b6d134d6e342a72b2dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_MEDIA_CAST_RECEIVER_SESSION_H_
#define CHROME_RENDERER_MEDIA_CAST_RECEIVER_SESSION_H_

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "chrome/renderer/media/cast_receiver_session_delegate.h"

namespace blink {
class WebMediaStream;
}

namespace media {
class AudioCapturerSource;
struct VideoCaptureFormat;
class VideoCapturerSource;
}

namespace net {
class IPEndPoint;
}

namespace base {
class DictionaryValue;
}

// This a render thread object, all methods, construction and
// destruction must happen on the render thread.
class CastReceiverSession : public base::RefCounted<CastReceiverSession> {
 public:
  CastReceiverSession();

  typedef base::Callback<void(scoped_refptr<media::AudioCapturerSource>,
                              scoped_ptr<media::VideoCapturerSource>)> StartCB;

  // Note that the cast receiver will start responding to
  // incoming network streams immediately, buffering input until
  // StartAudio/StartVideo is called.
  // Five first parameters are passed to cast receiver.
  // |start_callback| is called when initialization is done.
  // TODO(hubbe): Currently the audio component of the returned media
  // stream only the exact format that the sender is sending us.
  void Start(const media::cast::FrameReceiverConfig& audio_config,
             const media::cast::FrameReceiverConfig& video_config,
             const net::IPEndPoint& local_endpoint,
             const net::IPEndPoint& remote_endpoint,
             scoped_ptr<base::DictionaryValue> options,
             const media::VideoCaptureFormat& capture_format,
             const StartCB& start_callback,
             const CastReceiverSessionDelegate::ErrorCallback& error_callback);

 private:
  class VideoCapturerSource;
  class AudioCapturerSource;
  friend class base::RefCounted<CastReceiverSession>;
  virtual ~CastReceiverSession();
  void StartAudio(scoped_refptr<CastReceiverAudioValve> audio_valve);

  void StartVideo(content::VideoCaptureDeliverFrameCB frame_callback);
  // Stop Video callbacks.
  // Note that this returns immediately, but callbacks do not stop immediately.
  void StopVideo();

  media::cast::FrameReceiverConfig audio_config_;
  media::cast::FrameReceiverConfig video_config_;
  scoped_ptr<CastReceiverSessionDelegate> delegate_;
  const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
  media::VideoCaptureFormat format_;

  DISALLOW_COPY_AND_ASSIGN(CastReceiverSession);
};

#endif // CHROME_RENDERER_MEDIA_CAST_RECEIVER_SESSION_H_