blob: 9ba042010f78274e047f21e3098ccf7267456af7 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_MEDIASTREAMTRACK_H_
12#define WEBRTC_API_MEDIASTREAMTRACK_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
15
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/mediastreaminterface.h"
17#include "webrtc/api/notifier.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
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
perkjd61bf802016-03-24 03:16:19 -070028 std::string id() const override { return id_; }
29 MediaStreamTrackInterface::TrackState state() const override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030 return state_;
31 }
perkjd61bf802016-03-24 03:16:19 -070032 bool enabled() const override { return enabled_; }
33 bool set_enabled(bool enable) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034 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 }
perkjd61bf802016-03-24 03:16:19 -070041
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) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047 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
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054 private:
55 bool enabled_;
56 std::string id_;
57 MediaStreamTrackInterface::TrackState state_;
58};
59
60} // namespace webrtc
61
Henrik Kjellander15583c12016-02-10 10:53:12 +010062#endif // WEBRTC_API_MEDIASTREAMTRACK_H_