|
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_destination_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/media/media_stream_registry_interface.h" | |
12 #include "content/renderer/render_thread_impl.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaStreamRegistr y.h" | |
14 | |
15 using cricket::CaptureState; | |
16 using cricket::VideoFormat; | |
17 | |
18 static const cricket::FourCC kEffectColorFormat = cricket::FOURCC_BGRA; | |
19 | |
20 namespace content { | |
21 | |
22 PpFrameWriter::PpFrameWriter() | |
23 : started_(false) {} | |
24 | |
25 PpFrameWriter::~PpFrameWriter() {} | |
26 | |
27 CaptureState PpFrameWriter::Start(const VideoFormat& capture_format) { | |
28 if (started_) { | |
29 LOG(ERROR) << "PpFrameWriter::Start - " | |
30 << "Got a StartCapture when already started!"; | |
31 return cricket::CS_FAILED; | |
32 } | |
33 started_ = true; | |
34 return cricket::CS_STARTING; | |
35 } | |
36 | |
37 void PpFrameWriter::Stop() { | |
38 started_ = false; | |
39 SignalStateChange(this, cricket::CS_STOPPED); | |
40 } | |
41 | |
42 bool PpFrameWriter::IsRunning() { | |
43 return started_; | |
44 } | |
45 | |
46 bool PpFrameWriter::GetPreferredFourccs(std::vector<uint32>* fourccs) { | |
47 if (!fourccs) { | |
48 LOG(ERROR) << "PpFrameWriter::GetPreferredFourccs - " | |
49 << "fourccs is NULL."; | |
50 return false; | |
51 } | |
52 // The effects plugin output BGRA. | |
53 fourccs->push_back(kEffectColorFormat); | |
54 return true; | |
55 } | |
56 | |
57 bool PpFrameWriter::GetBestCaptureFormat(const VideoFormat& desired, | |
58 VideoFormat* best_format) { | |
59 if (!best_format) { | |
60 LOG(ERROR) << "PpFrameWriter::GetBestCaptureFormat - " | |
61 << "best_format is NULL."; | |
62 return false; | |
63 return false; | |
64 } | |
65 | |
66 // Use the desired format as the best format. | |
67 // TODO(ronghuawu): How to handle this better? | |
68 best_format->width = desired.width; | |
69 best_format->height = desired.height; | |
70 best_format->fourcc = kEffectColorFormat; | |
71 best_format->interval = desired.interval; | |
72 return true; | |
73 } | |
74 | |
75 bool PpFrameWriter::IsScreencast() const { | |
76 return false; | |
77 } | |
78 | |
79 void PpFrameWriter::PutFrame(cricket::CapturedFrame* frame) { | |
80 if (!started_) { | |
wjia(left Chromium)
2013/04/30 18:32:11
Is there race condition to access |started_|? AFAI
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
Stop will be called from a libjingle worker thread
| |
81 LOG(ERROR) << "Got a PutFrame when the capturer is not started!"; | |
82 return; | |
83 } | |
84 | |
85 // This signals to libJingle that a new VideoFrame is available. | |
86 // libJingle have no assumptions on what thread this signal come from. | |
87 SignalFrameCaptured(this, frame); | |
88 } | |
89 | |
90 VideoDestinationHandler::VideoDestinationHandler( | |
91 MediaStreamDependencyFactory* factory, | |
92 MediaStreamRegistryInterface* registry) | |
wjia(left Chromium)
2013/04/30 18:32:11
What's the life time of factory and registry? How
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
VideoDestinationHandler, the factory and the regis
| |
93 : factory_(factory), | |
94 registry_(registry) { | |
95 ASSERT(factory_ != NULL); | |
96 } | |
97 | |
98 bool VideoDestinationHandler::Open( | |
99 const std::string& url, FrameWriterInterface** frame_writer) { | |
100 WebKit::WebMediaStream stream; | |
101 if (registry_) { | |
102 stream = registry_->GetMediaStream(url); | |
103 } else { | |
104 stream = | |
105 WebKit::WebMediaStreamRegistry::lookupMediaStreamDescriptor(GURL(url)); | |
106 } | |
107 if (stream.isNull() || !stream.extraData()) { | |
108 LOG(ERROR) << "VideoDestinationHandler::Open - invalid url: " << url; | |
109 return false; | |
110 } | |
111 | |
112 // Create a new native video track and add it to |stream|. | |
113 std::string track_id = talk_base::ToString(talk_base::CreateRandomId64()); | |
114 PpFrameWriter* capturer = new PpFrameWriter(); | |
wjia(left Chromium)
2013/04/30 18:32:11
Does it make sense to make PpFrameWriter class int
Ronghua Wu (Left Chromium)
2013/04/30 22:42:17
It makes sense. But also what to have unit tests f
| |
115 if (!factory_->AddNativeVideoMediaTrack(track_id, &stream, capturer)) { | |
116 delete capturer; | |
117 return false; | |
118 } | |
119 | |
120 *frame_writer = capturer; | |
121 return true; | |
122 } | |
123 | |
124 VideoDestinationHandler::~VideoDestinationHandler() { | |
125 } | |
126 | |
127 } // namespace content | |
128 | |
OLD | NEW |