|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 #include "content/renderer/media/video_source_handler.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/logging.h" | |
10 #include "content/renderer/media/media_stream_dependency_factory.h" | |
11 #include "content/renderer/render_thread_impl.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" | |
13 | |
14 using cricket::VideoFrame; | |
15 using webrtc::VideoSourceInterface; | |
16 | |
17 namespace content { | |
18 | |
19 PpFrameReader::PpFrameReader() { | |
20 } | |
21 | |
22 PpFrameReader::~PpFrameReader() { | |
23 } | |
24 | |
25 bool PpFrameReader::SetSize(int width, int height, int reserved) { | |
26 return true; | |
27 } | |
28 | |
29 bool PpFrameReader::RenderFrame(const VideoFrame* frame) { | |
30 base::AutoLock auto_lock(lock_); | |
31 // Make a shallow copy of the frame. Both frames will share a single | |
32 // reference-counted frame buffer. | |
33 last_frame_.reset(frame->Copy()); | |
34 return true; | |
35 } | |
36 | |
37 bool PpFrameReader::GetFrame(VideoFrame** frame) { | |
38 base::AutoLock auto_lock(lock_); | |
39 *frame = last_frame_.release(); | |
40 return true; | |
41 } | |
42 | |
43 VideoSourceHandler::VideoSourceHandler( | |
44 MediaStreamDependencyFactory* factory, | |
45 MediaStreamRegistryInterface* registry) | |
wjia(left Chromium)
2013/04/30 18:32:11
How is it guaranteed that we won't have use-after-
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
The VideoSourceHandler doesn't take the ownership
| |
46 : factory_(factory), | |
47 registry_(registry) { | |
48 ASSERT(factory_ != NULL); | |
49 } | |
50 | |
51 bool VideoSourceHandler::Open(const std::string& url, | |
52 FrameReaderInterface** frame_reader) { | |
53 scoped_refptr<webrtc::VideoSourceInterface> source = GetFirstVideoSource(url); | |
54 if (!source.get()) { | |
55 return false; | |
56 } | |
57 PpFrameReader* new_frame_reader = new PpFrameReader(); | |
wjia(left Chromium)
2013/04/30 18:32:11
It seems that PpFrameReader is an internal class t
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
Correct, I left it in the header more for the test
| |
58 source->AddSink(new_frame_reader); | |
59 *frame_reader = new_frame_reader; | |
60 return true; | |
61 } | |
62 | |
63 bool VideoSourceHandler::Close(const std::string& url, | |
64 FrameReaderInterface* frame_reader) { | |
65 scoped_refptr<webrtc::VideoSourceInterface> source = GetFirstVideoSource(url); | |
66 if (!source.get()) { | |
67 return false; | |
68 } | |
69 PpFrameReader* pp_frame_reader = static_cast<PpFrameReader*>(frame_reader); | |
70 source->RemoveSink(pp_frame_reader); | |
71 return true; | |
72 } | |
73 | |
74 scoped_refptr<VideoSourceInterface> VideoSourceHandler::GetFirstVideoSource( | |
wjia(left Chromium)
2013/04/30 18:32:11
Is it possible move this function into media_strea
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
I think MediaStreamImpl is suppose be used by WebK
| |
75 const std::string& url) { | |
76 scoped_refptr<webrtc::VideoSourceInterface> source; | |
77 WebKit::WebMediaStream stream; | |
78 if (registry_) { | |
79 stream = registry_->GetMediaStream(url); | |
80 } else { | |
81 stream = | |
82 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(GURL(url)); | |
83 } | |
84 if (stream.isNull() || !stream.extraData()) { | |
85 LOG(ERROR) << "GetFirstVideoSource - invalid url: " << url; | |
86 return source; | |
87 } | |
88 | |
89 // Get the first video track from the stream. | |
90 MediaStreamExtraData* extra_data = | |
91 static_cast<MediaStreamExtraData*>(stream.extraData()); | |
92 if (!extra_data) { | |
93 LOG(ERROR) << "GetFirstVideoSource - MediaStreamExtraData is NULL."; | |
94 return source; | |
95 } | |
96 webrtc::MediaStreamInterface* native_stream = extra_data->stream(); | |
97 if (!native_stream) { | |
98 LOG(ERROR) << "GetFirstVideoSource - native stream is NULL."; | |
99 return source; | |
100 } | |
101 webrtc::VideoTrackVector native_video_tracks = | |
102 native_stream->GetVideoTracks(); | |
103 if (native_video_tracks.empty()) { | |
104 LOG(ERROR) << "GetFirstVideoSource - stream has no video track."; | |
105 return source; | |
106 } | |
107 source = native_video_tracks[0]->GetSource(); | |
108 return source; | |
109 } | |
110 | |
111 } // namespace content | |
112 | |
OLD | NEW |