media_stream_track.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  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. #ifndef PC_MEDIA_STREAM_TRACK_H_
  11. #define PC_MEDIA_STREAM_TRACK_H_
  12. #include <string>
  13. #include "api/media_stream_interface.h"
  14. #include "api/notifier.h"
  15. namespace webrtc {
  16. // MediaTrack implements the interface common to AudioTrackInterface and
  17. // VideoTrackInterface.
  18. template <typename T>
  19. class MediaStreamTrack : public Notifier<T> {
  20. public:
  21. typedef typename T::TrackState TypedTrackState;
  22. std::string id() const override { return id_; }
  23. MediaStreamTrackInterface::TrackState state() const override {
  24. return state_;
  25. }
  26. bool enabled() const override { return enabled_; }
  27. bool set_enabled(bool enable) override {
  28. bool fire_on_change = (enable != enabled_);
  29. enabled_ = enable;
  30. if (fire_on_change) {
  31. Notifier<T>::FireOnChanged();
  32. }
  33. return fire_on_change;
  34. }
  35. protected:
  36. explicit MediaStreamTrack(const std::string& id)
  37. : enabled_(true), id_(id), state_(MediaStreamTrackInterface::kLive) {}
  38. bool set_state(MediaStreamTrackInterface::TrackState new_state) {
  39. bool fire_on_change = (state_ != new_state);
  40. state_ = new_state;
  41. if (fire_on_change)
  42. Notifier<T>::FireOnChanged();
  43. return true;
  44. }
  45. private:
  46. bool enabled_;
  47. std::string id_;
  48. MediaStreamTrackInterface::TrackState state_;
  49. };
  50. } // namespace webrtc
  51. #endif // PC_MEDIA_STREAM_TRACK_H_