1 /*
2  *  Copyright 2012 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 
11 #ifndef PC_VIDEO_TRACK_H_
12 #define PC_VIDEO_TRACK_H_
13 
14 #include <string>
15 
16 #include "api/media_stream_interface.h"
17 #include "api/media_stream_track.h"
18 #include "api/scoped_refptr.h"
19 #include "api/sequence_checker.h"
20 #include "api/video/video_frame.h"
21 #include "api/video/video_sink_interface.h"
22 #include "api/video/video_source_interface.h"
23 #include "media/base/video_source_base.h"
24 #include "rtc_base/thread.h"
25 #include "rtc_base/thread_annotations.h"
26 
27 namespace webrtc {
28 
29 class VideoTrack : public MediaStreamTrack<VideoTrackInterface>,
30                    public rtc::VideoSourceBase,
31                    public ObserverInterface {
32  public:
33   static rtc::scoped_refptr<VideoTrack> Create(
34       const std::string& label,
35       VideoTrackSourceInterface* source,
36       rtc::Thread* worker_thread);
37 
38   void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
39                        const rtc::VideoSinkWants& wants) override;
40   void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
41 
GetSource()42   VideoTrackSourceInterface* GetSource() const override {
43     return video_source_.get();
44   }
45   ContentHint content_hint() const override;
46   void set_content_hint(ContentHint hint) override;
47   bool set_enabled(bool enable) override;
48   std::string kind() const override;
49 
50  protected:
51   VideoTrack(const std::string& id,
52              VideoTrackSourceInterface* video_source,
53              rtc::Thread* worker_thread);
54   ~VideoTrack();
55 
56  private:
57   // Implements ObserverInterface. Observes |video_source_| state.
58   void OnChanged() override;
59 
60   rtc::Thread* const worker_thread_;
61   SequenceChecker signaling_thread_checker_;
62   rtc::scoped_refptr<VideoTrackSourceInterface> video_source_;
63   ContentHint content_hint_ RTC_GUARDED_BY(signaling_thread_checker_);
64 };
65 
66 }  // namespace webrtc
67 
68 #endif  // PC_VIDEO_TRACK_H_
69