From 9cb42c86909c72efd6391d6b38bf0ca8d449510c Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Sun, 11 Oct 2020 13:03:47 +0000 Subject: [PATCH] Move pc/media_stream_track.h to the api/ directory This file is being accessed from Chrome. Moving it lessens the dependency of Chrome on files in the pc/ directory, and allows easier refactoring of pc/. Bug: webrtc:11967 Change-Id: Iccd568f84e9cf4086e37c58db1b4cba6c376f413 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/187489 Reviewed-by: Mirko Bonadei Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/master@{#32378} --- api/BUILD.gn | 1 + api/media_stream_track.h | 63 ++++++++++++++++++++++++++++++ pc/audio_track.h | 2 +- pc/media_stream_track.h | 55 ++------------------------ pc/rtc_stats_collector_unittest.cc | 2 +- pc/stats_collector_unittest.cc | 2 +- pc/video_track.h | 2 +- 7 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 api/media_stream_track.h diff --git a/api/BUILD.gn b/api/BUILD.gn index 377e1e21de..cc5975f59e 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -98,6 +98,7 @@ rtc_library("media_stream_interface") { sources = [ "media_stream_interface.cc", "media_stream_interface.h", + "media_stream_track.h", "notifier.h", ] deps = [ diff --git a/api/media_stream_track.h b/api/media_stream_track.h new file mode 100644 index 0000000000..738f034143 --- /dev/null +++ b/api/media_stream_track.h @@ -0,0 +1,63 @@ +/* + * Copyright 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_MEDIA_STREAM_TRACK_H_ +#define API_MEDIA_STREAM_TRACK_H_ + +#include + +#include "api/media_stream_interface.h" +#include "api/notifier.h" + +namespace webrtc { + +// MediaTrack implements the interface common to AudioTrackInterface and +// VideoTrackInterface. +template +class MediaStreamTrack : public Notifier { + public: + typedef typename T::TrackState TypedTrackState; + + std::string id() const override { return id_; } + MediaStreamTrackInterface::TrackState state() const override { + return state_; + } + bool enabled() const override { return enabled_; } + bool set_enabled(bool enable) override { + bool fire_on_change = (enable != enabled_); + enabled_ = enable; + if (fire_on_change) { + Notifier::FireOnChanged(); + } + return fire_on_change; + } + void set_ended() { set_state(MediaStreamTrackInterface::TrackState::kEnded); } + + protected: + explicit MediaStreamTrack(const std::string& id) + : enabled_(true), id_(id), state_(MediaStreamTrackInterface::kLive) {} + + bool set_state(MediaStreamTrackInterface::TrackState new_state) { + bool fire_on_change = (state_ != new_state); + state_ = new_state; + if (fire_on_change) + Notifier::FireOnChanged(); + return true; + } + + private: + bool enabled_; + const std::string id_; + MediaStreamTrackInterface::TrackState state_; +}; + +} // namespace webrtc + +#endif // API_MEDIA_STREAM_TRACK_H_ diff --git a/pc/audio_track.h b/pc/audio_track.h index a0388e8cad..8cff79e8b9 100644 --- a/pc/audio_track.h +++ b/pc/audio_track.h @@ -14,8 +14,8 @@ #include #include "api/media_stream_interface.h" +#include "api/media_stream_track.h" #include "api/scoped_refptr.h" -#include "pc/media_stream_track.h" #include "rtc_base/thread_checker.h" namespace webrtc { diff --git a/pc/media_stream_track.h b/pc/media_stream_track.h index fd63569aac..1316b51365 100644 --- a/pc/media_stream_track.h +++ b/pc/media_stream_track.h @@ -1,5 +1,5 @@ /* - * Copyright 2011 The WebRTC project authors. All Rights Reserved. + * Copyright 2020 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -7,58 +7,9 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ - #ifndef PC_MEDIA_STREAM_TRACK_H_ #define PC_MEDIA_STREAM_TRACK_H_ - -#include - -#include "api/media_stream_interface.h" -#include "api/notifier.h" -#include "rtc_base/logging.h" - -namespace webrtc { - -// MediaTrack implements the interface common to AudioTrackInterface and -// VideoTrackInterface. -template -class MediaStreamTrack : public Notifier { - public: - typedef typename T::TrackState TypedTrackState; - - std::string id() const override { return id_; } - MediaStreamTrackInterface::TrackState state() const override { - return state_; - } - bool enabled() const override { return enabled_; } - bool set_enabled(bool enable) override { - bool fire_on_change = (enable != enabled_); - enabled_ = enable; - if (fire_on_change) { - Notifier::FireOnChanged(); - } - return fire_on_change; - } - void set_ended() { set_state(MediaStreamTrackInterface::TrackState::kEnded); } - - protected: - explicit MediaStreamTrack(const std::string& id) - : enabled_(true), id_(id), state_(MediaStreamTrackInterface::kLive) {} - - bool set_state(MediaStreamTrackInterface::TrackState new_state) { - bool fire_on_change = (state_ != new_state); - state_ = new_state; - if (fire_on_change) - Notifier::FireOnChanged(); - return true; - } - - private: - bool enabled_; - const std::string id_; - MediaStreamTrackInterface::TrackState state_; -}; - -} // namespace webrtc +// Temporary header forwarding +#include "api/media_stream_track.h" #endif // PC_MEDIA_STREAM_TRACK_H_ diff --git a/pc/rtc_stats_collector_unittest.cc b/pc/rtc_stats_collector_unittest.cc index becf7350a3..6d71e2acd1 100644 --- a/pc/rtc_stats_collector_unittest.cc +++ b/pc/rtc_stats_collector_unittest.cc @@ -22,6 +22,7 @@ #include "absl/memory/memory.h" #include "absl/strings/str_replace.h" +#include "api/media_stream_track.h" #include "api/rtp_parameters.h" #include "api/stats/rtc_stats_report.h" #include "api/stats/rtcstats_objects.h" @@ -31,7 +32,6 @@ #include "p2p/base/p2p_constants.h" #include "p2p/base/port.h" #include "pc/media_stream.h" -#include "pc/media_stream_track.h" #include "pc/test/fake_data_channel_provider.h" #include "pc/test/fake_peer_connection_for_stats.h" #include "pc/test/mock_data_channel.h" diff --git a/pc/stats_collector_unittest.cc b/pc/stats_collector_unittest.cc index a5666ff6b6..3767081b56 100644 --- a/pc/stats_collector_unittest.cc +++ b/pc/stats_collector_unittest.cc @@ -19,12 +19,12 @@ #include "api/audio_codecs/audio_encoder.h" #include "api/candidate.h" #include "api/data_channel_interface.h" +#include "api/media_stream_track.h" #include "api/scoped_refptr.h" #include "call/call.h" #include "media/base/media_channel.h" #include "modules/audio_processing/include/audio_processing_statistics.h" #include "pc/media_stream.h" -#include "pc/media_stream_track.h" #include "pc/sctp_data_channel.h" #include "pc/test/fake_peer_connection_for_stats.h" #include "pc/test/fake_video_track_source.h" diff --git a/pc/video_track.h b/pc/video_track.h index 90e0758a6c..b7835dee29 100644 --- a/pc/video_track.h +++ b/pc/video_track.h @@ -14,12 +14,12 @@ #include #include "api/media_stream_interface.h" +#include "api/media_stream_track.h" #include "api/scoped_refptr.h" #include "api/video/video_frame.h" #include "api/video/video_sink_interface.h" #include "api/video/video_source_interface.h" #include "media/base/video_source_base.h" -#include "pc/media_stream_track.h" #include "rtc_base/thread.h" #include "rtc_base/thread_annotations.h" #include "rtc_base/thread_checker.h"