Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: content/renderer/media/video_track_adapter.h

Issue 246433006: Change MediaStreamVideoSource to output different resolutions to different tracks depending on the … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed missed comments. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_
6 #define CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_
7
8 #include <vector>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/renderer/media/media_stream_video_track.h"
13 #include "media/base/video_frame.h"
14
15 namespace content {
16
17 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for
18 // adapting the video resolution from a source implementation to the resolution
19 // a track requires. Different tracks can have different resolution constraints.
20 // The constraints can be set as max width and height as well as max and min
21 // aspect ratio.
22 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on
23 // the IO-thread.
24 // Adaptations is done by wrapping the original media::VideoFrame in a new
25 // media::VideoFrame with a new visible_rect and natural_size.
26 class VideoTrackAdapter
27 : public base::RefCountedThreadSafe<VideoTrackAdapter> {
28 public:
29 explicit VideoTrackAdapter(
30 const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
31
32 // Register |track| to receive video frames in |frame_callback| with
33 // a resolution within the boundaries of the arguments.
34 // Must be called on the main render thread. |frame_callback| is guaranteed to
35 // be released on the main render thread.
36 void AddTrack(const MediaStreamVideoTrack* track,
37 VideoCaptureDeliverFrameCB frame_callback,
38 int max_width, int max_height,
39 double min_aspect_ratio,
40 double max_aspect_ratio);
41 void RemoveTrack(const MediaStreamVideoTrack* track);
42
43 // Delivers |frame| to all tracks that have registered a callback.
44 // Must be called on the IO-thread.
45 void DeliverFrameOnIO(
46 const scoped_refptr<media::VideoFrame>& frame,
47 const media::VideoCaptureFormat& format);
48
49 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() {
50 DCHECK(thread_checker_.CalledOnValidThread());
51 return io_message_loop_;
52 }
53
54 private:
55 virtual ~VideoTrackAdapter();
56 friend class base::RefCountedThreadSafe<VideoTrackAdapter>;
57
58 void SetRenderMessageLoopOnIo(
59 const scoped_refptr<base::MessageLoopProxy>& renderer_message_loop);
60 void AddTrackOnIO(
61 const MediaStreamVideoTrack* track,
62 VideoCaptureDeliverFrameCB frame_callback,
63 int max_width, int max_height,
64 double min_aspect_ratio,
65 double max_aspect_ratio);
66 void RemoveTrackOnIO(const MediaStreamVideoTrack* track);
67
68 // |thread_checker_| is bound to the main render thread.
69 base::ThreadChecker thread_checker_;
70
71 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
72
73 // |renderer_message_loop_| is set on the IO thread and used
74 // to ensure that VideoCaptureDeliverFrameCBis released on the main render
75 // thread.
76 scoped_refptr<base::MessageLoopProxy> renderer_message_loop_;
77
78 // VideoFrameResolutionAdapter is an inner class that is created on the main
79 // render thread but operates on the IO-thread. It does the resolution
80 // adaptation and delivers frames to all registered tracks on the IO-thread.
81 class VideoFrameResolutionAdapter;
82 typedef std::vector<scoped_refptr<VideoFrameResolutionAdapter> >
83 FrameAdapters;
84 FrameAdapters adapters_;
85
86 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter);
87 };
88
89 } // namespace content
90
91 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698