| 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 |
| 11 | #ifndef API_MEDIA_STREAM_TRACK_H_ |
| 12 | #define API_MEDIA_STREAM_TRACK_H_ |
| 13 |
| 14 | #include <string> |
| 15 |
| 16 | #include "api/media_stream_interface.h" |
| 17 | #include "api/notifier.h" |
| 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 | 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 | void set_ended() { set_state(MediaStreamTrackInterface::TrackState::kEnded); } |
| 42 |
| 43 | protected: |
| 44 | explicit MediaStreamTrack(const std::string& id) |
| 45 | : enabled_(true), id_(id), state_(MediaStreamTrackInterface::kLive) {} |
| 46 |
| 47 | bool set_state(MediaStreamTrackInterface::TrackState new_state) { |
| 48 | bool fire_on_change = (state_ != new_state); |
| 49 | state_ = new_state; |
| 50 | if (fire_on_change) |
| 51 | Notifier<T>::FireOnChanged(); |
| 52 | return true; |
| 53 | } |
| 54 |
| 55 | private: |
| 56 | bool enabled_; |
| 57 | const std::string id_; |
| 58 | MediaStreamTrackInterface::TrackState state_; |
| 59 | }; |
| 60 |
| 61 | } // namespace webrtc |
| 62 |
| 63 | #endif // API_MEDIA_STREAM_TRACK_H_ |
| 64 |