henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_API_MEDIASTREAMTRACK_H_ |
| 12 | #define WEBRTC_API_MEDIASTREAMTRACK_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 16 | #include "webrtc/api/mediastreaminterface.h" |
| 17 | #include "webrtc/api/notifier.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // MediaTrack implements the interface common to AudioTrackInterface and |
| 22 | // VideoTrackInterface. |
| 23 | template <typename T> |
| 24 | class MediaStreamTrack : public Notifier<T> { |
| 25 | public: |
| 26 | typedef typename T::TrackState TypedTrackState; |
| 27 | |
| 28 | virtual std::string id() const { return id_; } |
| 29 | virtual MediaStreamTrackInterface::TrackState state() const { |
| 30 | return state_; |
| 31 | } |
| 32 | virtual bool enabled() const { return enabled_; } |
| 33 | virtual bool set_enabled(bool enable) { |
| 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 | virtual bool set_state(MediaStreamTrackInterface::TrackState new_state) { |
| 42 | bool fire_on_change = (state_ != new_state); |
| 43 | state_ = new_state; |
| 44 | if (fire_on_change) |
| 45 | Notifier<T>::FireOnChanged(); |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | protected: |
| 50 | explicit MediaStreamTrack(const std::string& id) |
perkj | c8f952d | 2016-03-23 00:33:56 -0700 | [diff] [blame] | 51 | : enabled_(true), id_(id), state_(MediaStreamTrackInterface::kLive) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | bool enabled_; |
| 55 | std::string id_; |
| 56 | MediaStreamTrackInterface::TrackState state_; |
| 57 | }; |
| 58 | |
| 59 | } // namespace webrtc |
| 60 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 61 | #endif // WEBRTC_API_MEDIASTREAMTRACK_H_ |