blob: 358d89a25b61096fbafca30e24350908ed490343 [file] [log] [blame]
ossu7bb87ee2017-01-23 04:56:25 -08001/*
2 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_MEDIA_STREAM_TRACK_H_
12#define PC_MEDIA_STREAM_TRACK_H_
ossu7bb87ee2017-01-23 04:56:25 -080013
14#include <string>
15
Steve Anton10542f22019-01-11 09:11:00 -080016#include "api/media_stream_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/notifier.h"
ossu7bb87ee2017-01-23 04:56:25 -080018
19namespace webrtc {
20
21// MediaTrack implements the interface common to AudioTrackInterface and
22// VideoTrackInterface.
23template <typename T>
24class MediaStreamTrack : public Notifier<T> {
25 public:
26 typedef typename T::TrackState TypedTrackState;
27
28 std::string id() const override { return id_; }
29 MediaStreamTrackInterface::TrackState state() const override {
30 return state_;
31 }
32 bool enabled() const override { return enabled_; }
33 bool set_enabled(bool enable) override {
34 bool fire_on_change = (enable != enabled_);
35 enabled_ = enable;
36 if (fire_on_change) {
37 Notifier<T>::FireOnChanged();
38 }
39 return fire_on_change;
40 }
41
42 protected:
43 explicit MediaStreamTrack(const std::string& id)
44 : enabled_(true), id_(id), state_(MediaStreamTrackInterface::kLive) {}
45
46 bool set_state(MediaStreamTrackInterface::TrackState new_state) {
47 bool fire_on_change = (state_ != new_state);
48 state_ = new_state;
49 if (fire_on_change)
50 Notifier<T>::FireOnChanged();
51 return true;
52 }
53
54 private:
55 bool enabled_;
56 std::string id_;
57 MediaStreamTrackInterface::TrackState state_;
58};
59
60} // namespace webrtc
61
Steve Anton10542f22019-01-11 09:11:00 -080062#endif // PC_MEDIA_STREAM_TRACK_H_