Return Windows error code when create-process fails.
[chromium-blink-merge.git] / chrome / renderer / media / cast_session.h
blobacd04814d46347a54ae14519833cc645f2753e11
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 #ifndef CHROME_RENDERER_MEDIA_CAST_SESSION_H_
6 #define CHROME_RENDERER_MEDIA_CAST_SESSION_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "net/base/ip_endpoint.h"
16 namespace base {
17 class BinaryValue;
18 class DictionaryValue;
19 class SingleThreadTaskRunner;
20 } // namespace base
22 namespace media {
23 class VideoFrame;
24 namespace cast {
25 class AudioFrameInput;
26 class VideoFrameInput;
27 struct AudioSenderConfig;
28 struct VideoSenderConfig;
29 } // namespace cast
30 } // namespace media
32 namespace content {
33 class P2PSocketClient;
34 } // namespace content
36 class CastSessionDelegate;
38 // This class represents a Cast session and allows the session to be
39 // configured on the main thread. Actual work is forwarded to
40 // CastSessionDelegate on the IO thread.
41 class CastSession : public base::RefCounted<CastSession> {
42 public:
43 typedef base::Callback<void(const scoped_refptr<
44 media::cast::AudioFrameInput>&)> AudioFrameInputAvailableCallback;
45 typedef base::Callback<void(const scoped_refptr<
46 media::cast::VideoFrameInput>&)> VideoFrameInputAvailableCallback;
47 typedef base::Callback<void(const std::vector<char>&)> SendPacketCallback;
48 typedef base::Callback<void(scoped_ptr<base::BinaryValue>)> EventLogsCallback;
49 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> StatsCallback;
50 typedef base::Callback<void(const std::string&)> ErrorCallback;
52 CastSession();
54 // Start encoding of audio and video using the provided configuration.
56 // When Cast sender is started and ready to be used
57 // media::cast::FrameInput will be given through |callback|.
58 // If it encounters an error, |error_callback| will be invoked with the
59 // error message. Both |callback| and |error_callback| will be made on
60 // the main thread.
61 // |StartUDP()| must be called before these methods.
62 void StartAudio(const media::cast::AudioSenderConfig& config,
63 const AudioFrameInputAvailableCallback& callback,
64 const ErrorCallback& error_callback);
65 void StartVideo(const media::cast::VideoSenderConfig& config,
66 const VideoFrameInputAvailableCallback& callback,
67 const ErrorCallback& error_callback);
69 // This will create the Cast transport and connect to |remote_endpoint|.
70 // |options| is a dictionary which contain optional configuration for the
71 // udp transport.
72 // Must be called before initialization of audio or video.
73 void StartUDP(const net::IPEndPoint& remote_endpoint,
74 scoped_ptr<base::DictionaryValue> options,
75 const ErrorCallback& error_callback);
77 // Creates or destroys event subscriber for the audio or video stream.
78 // |is_audio|: true if the event subscriber is for audio. Video otherwise.
79 // |enable|: If true, creates an event subscriber. Otherwise destroys
80 // existing subscriber and discards logs.
81 void ToggleLogging(bool is_audio, bool enable);
83 // Returns raw event logs in serialized format for either the audio or video
84 // stream since last call and returns result in |callback|. Also attaches
85 // |extra_data| to the log.
86 void GetEventLogsAndReset(bool is_audio,
87 const std::string& extra_data, const EventLogsCallback& callback);
89 // Returns stats in a DictionaryValue format for either the audio or video
90 // stream since last call and returns result in |callback|.
91 void GetStatsAndReset(bool is_audio, const StatsCallback& callback);
93 private:
94 friend class base::RefCounted<CastSession>;
95 virtual ~CastSession();
97 // This member should never be dereferenced on the main thread.
98 // CastSessionDelegate lives only on the IO thread. It is always
99 // safe to post task on the IO thread to access CastSessionDelegate
100 // because it is owned by this object.
101 scoped_ptr<CastSessionDelegate> delegate_;
103 // Proxy to the IO task runner.
104 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
106 DISALLOW_COPY_AND_ASSIGN(CastSession);
109 #endif // CHROME_RENDERER_MEDIA_CAST_SESSION_H_