blob: 01c3da8e0e815f2c40ccda6885ef18ca236e96bd [file] [log] [blame]
// Copyright 2013 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.
#include <memory>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "media/cast/cast_config.h"
#include "media/cast/constants.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
namespace base {
class BinaryValue;
class DictionaryValue;
class CastAudioSink;
class CastSession;
class CastVideoSink;
// This object represents a RTP stream that encodes and optionally
// encrypt audio or video data from a WebMediaStreamTrack.
// Note that this object does not actually output packets. It allows
// configuration of encoding and RTP parameters and control such a logical
// stream.
class CastRtpStream {
typedef base::Callback<void(const std::string&)> ErrorCallback;
static bool IsHardwareVP8EncodingSupported();
static bool IsHardwareH264EncodingSupported();
CastRtpStream(const blink::WebMediaStreamTrack& track,
const scoped_refptr<CastSession>& session);
// Return parameters currently supported by this stream.
std::vector<media::cast::FrameSenderConfig> GetSupportedConfigs();
// Begin encoding of media stream and then submit the encoded streams
// to underlying transport.
// When the stream is started |start_callback| is called.
// When the stream is stopped |stop_callback| is called.
// When there is an error |error_callback| is called with a message.
void Start(const media::cast::FrameSenderConfig& config,
const base::Closure& start_callback,
const base::Closure& stop_callback,
const ErrorCallback& error_callback);
// Stop encoding.
void Stop();
// Enables or disables logging for this stream.
void ToggleLogging(bool enable);
// Get serialized raw events for this stream with |extra_data| attached,
// and invokes |callback| with the result.
void GetRawEvents(
const base::Callback<void(std::unique_ptr<base::BinaryValue>)>& callback,
const std::string& extra_data);
// Get stats in DictionaryValue format and invokves |callback| with
// the result.
void GetStats(const base::Callback<
void(std::unique_ptr<base::DictionaryValue>)>& callback);
// Return true if this track is an audio track. Return false if this
// track is a video track.
bool IsAudio() const;
void DidEncounterError(const std::string& message);
blink::WebMediaStreamTrack track_;
const scoped_refptr<CastSession> cast_session_;
std::unique_ptr<CastAudioSink> audio_sink_;
std::unique_ptr<CastVideoSink> video_sink_;
base::Closure stop_callback_;
ErrorCallback error_callback_;
base::WeakPtrFactory<CastRtpStream> weak_factory_;