OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 class AndroidVideoCapturer::FrameFactory : public cricket::VideoFrameFactory { | 43 class AndroidVideoCapturer::FrameFactory : public cricket::VideoFrameFactory { |
44 public: | 44 public: |
45 FrameFactory(const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) | 45 FrameFactory(const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) |
46 : start_time_(rtc::TimeNanos()), delegate_(delegate) { | 46 : start_time_(rtc::TimeNanos()), delegate_(delegate) { |
47 // Create a CapturedFrame that only contains header information, not the | 47 // Create a CapturedFrame that only contains header information, not the |
48 // actual pixel data. | 48 // actual pixel data. |
49 captured_frame_.pixel_height = 1; | 49 captured_frame_.pixel_height = 1; |
50 captured_frame_.pixel_width = 1; | 50 captured_frame_.pixel_width = 1; |
51 captured_frame_.data = nullptr; | 51 captured_frame_.data = nullptr; |
52 captured_frame_.data_size = cricket::CapturedFrame::kUnknownDataSize; | 52 captured_frame_.data_size = cricket::CapturedFrame::kUnknownDataSize; |
53 captured_frame_.fourcc = static_cast<uint32>(cricket::FOURCC_ANY); | 53 captured_frame_.fourcc = static_cast<uint32_t>(cricket::FOURCC_ANY); |
54 } | 54 } |
55 | 55 |
56 void UpdateCapturedFrame( | 56 void UpdateCapturedFrame( |
57 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | 57 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, |
58 int rotation, | 58 int rotation, |
59 int64 time_stamp_in_ns) { | 59 int64_t time_stamp_in_ns) { |
60 buffer_ = buffer; | 60 buffer_ = buffer; |
61 captured_frame_.width = buffer->width(); | 61 captured_frame_.width = buffer->width(); |
62 captured_frame_.height = buffer->height(); | 62 captured_frame_.height = buffer->height(); |
63 captured_frame_.elapsed_time = rtc::TimeNanos() - start_time_; | 63 captured_frame_.elapsed_time = rtc::TimeNanos() - start_time_; |
64 captured_frame_.time_stamp = time_stamp_in_ns; | 64 captured_frame_.time_stamp = time_stamp_in_ns; |
65 captured_frame_.rotation = rotation; | 65 captured_frame_.rotation = rotation; |
66 } | 66 } |
67 | 67 |
68 void ClearCapturedFrame() { | 68 void ClearCapturedFrame() { |
69 buffer_ = nullptr; | 69 buffer_ = nullptr; |
(...skipping 17 matching lines...) Expand all Loading... |
87 ShallowCenterCrop(buffer_, dst_width, dst_height), | 87 ShallowCenterCrop(buffer_, dst_width, dst_height), |
88 captured_frame->elapsed_time, captured_frame->time_stamp, | 88 captured_frame->elapsed_time, captured_frame->time_stamp, |
89 captured_frame->GetRotation())); | 89 captured_frame->GetRotation())); |
90 // Caller takes ownership. | 90 // Caller takes ownership. |
91 // TODO(magjed): Change CreateAliasedFrame() to return a rtc::scoped_ptr. | 91 // TODO(magjed): Change CreateAliasedFrame() to return a rtc::scoped_ptr. |
92 return apply_rotation_ ? frame->GetCopyWithRotationApplied()->Copy() | 92 return apply_rotation_ ? frame->GetCopyWithRotationApplied()->Copy() |
93 : frame.release(); | 93 : frame.release(); |
94 } | 94 } |
95 | 95 |
96 private: | 96 private: |
97 uint64 start_time_; | 97 uint64_t start_time_; |
98 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer_; | 98 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer_; |
99 cricket::CapturedFrame captured_frame_; | 99 cricket::CapturedFrame captured_frame_; |
100 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; | 100 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; |
101 }; | 101 }; |
102 | 102 |
103 AndroidVideoCapturer::AndroidVideoCapturer( | 103 AndroidVideoCapturer::AndroidVideoCapturer( |
104 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) | 104 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) |
105 : running_(false), | 105 : running_(false), |
106 delegate_(delegate), | 106 delegate_(delegate), |
107 frame_factory_(NULL), | 107 frame_factory_(NULL), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 delegate_->Stop(); | 166 delegate_->Stop(); |
167 current_state_ = cricket::CS_STOPPED; | 167 current_state_ = cricket::CS_STOPPED; |
168 SignalStateChange(this, current_state_); | 168 SignalStateChange(this, current_state_); |
169 } | 169 } |
170 | 170 |
171 bool AndroidVideoCapturer::IsRunning() { | 171 bool AndroidVideoCapturer::IsRunning() { |
172 RTC_CHECK(thread_checker_.CalledOnValidThread()); | 172 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
173 return running_; | 173 return running_; |
174 } | 174 } |
175 | 175 |
176 bool AndroidVideoCapturer::GetPreferredFourccs(std::vector<uint32>* fourccs) { | 176 bool AndroidVideoCapturer::GetPreferredFourccs(std::vector<uint32_t>* fourccs) { |
177 RTC_CHECK(thread_checker_.CalledOnValidThread()); | 177 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
178 fourccs->push_back(cricket::FOURCC_YV12); | 178 fourccs->push_back(cricket::FOURCC_YV12); |
179 return true; | 179 return true; |
180 } | 180 } |
181 | 181 |
182 void AndroidVideoCapturer::OnCapturerStarted(bool success) { | 182 void AndroidVideoCapturer::OnCapturerStarted(bool success) { |
183 RTC_CHECK(thread_checker_.CalledOnValidThread()); | 183 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
184 cricket::CaptureState new_state = | 184 cricket::CaptureState new_state = |
185 success ? cricket::CS_RUNNING : cricket::CS_FAILED; | 185 success ? cricket::CS_RUNNING : cricket::CS_FAILED; |
186 if (new_state == current_state_) | 186 if (new_state == current_state_) |
187 return; | 187 return; |
188 current_state_ = new_state; | 188 current_state_ = new_state; |
189 | 189 |
190 // TODO(perkj): SetCaptureState can not be used since it posts to |thread_|. | 190 // TODO(perkj): SetCaptureState can not be used since it posts to |thread_|. |
191 // But |thread_ | is currently just the thread that happened to create the | 191 // But |thread_ | is currently just the thread that happened to create the |
192 // cricket::VideoCapturer. | 192 // cricket::VideoCapturer. |
193 SignalStateChange(this, new_state); | 193 SignalStateChange(this, new_state); |
194 } | 194 } |
195 | 195 |
196 void AndroidVideoCapturer::OnIncomingFrame( | 196 void AndroidVideoCapturer::OnIncomingFrame( |
197 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer, | 197 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer, |
198 int rotation, | 198 int rotation, |
199 int64 time_stamp) { | 199 int64_t time_stamp) { |
200 RTC_CHECK(thread_checker_.CalledOnValidThread()); | 200 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
201 frame_factory_->UpdateCapturedFrame(buffer, rotation, time_stamp); | 201 frame_factory_->UpdateCapturedFrame(buffer, rotation, time_stamp); |
202 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); | 202 SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); |
203 frame_factory_->ClearCapturedFrame(); | 203 frame_factory_->ClearCapturedFrame(); |
204 } | 204 } |
205 | 205 |
206 void AndroidVideoCapturer::OnOutputFormatRequest( | 206 void AndroidVideoCapturer::OnOutputFormatRequest( |
207 int width, int height, int fps) { | 207 int width, int height, int fps) { |
208 RTC_CHECK(thread_checker_.CalledOnValidThread()); | 208 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
209 const cricket::VideoFormat& current = video_adapter()->output_format(); | 209 const cricket::VideoFormat& current = video_adapter()->output_format(); |
210 cricket::VideoFormat format( | 210 cricket::VideoFormat format( |
211 width, height, cricket::VideoFormat::FpsToInterval(fps), current.fourcc); | 211 width, height, cricket::VideoFormat::FpsToInterval(fps), current.fourcc); |
212 video_adapter()->OnOutputFormatRequest(format); | 212 video_adapter()->OnOutputFormatRequest(format); |
213 } | 213 } |
214 | 214 |
215 bool AndroidVideoCapturer::GetBestCaptureFormat( | 215 bool AndroidVideoCapturer::GetBestCaptureFormat( |
216 const cricket::VideoFormat& desired, | 216 const cricket::VideoFormat& desired, |
217 cricket::VideoFormat* best_format) { | 217 cricket::VideoFormat* best_format) { |
218 // Delegate this choice to VideoCapturerAndroid.startCapture(). | 218 // Delegate this choice to VideoCapturerAndroid.startCapture(). |
219 *best_format = desired; | 219 *best_format = desired; |
220 return true; | 220 return true; |
221 } | 221 } |
222 | 222 |
223 } // namespace webrtc | 223 } // namespace webrtc |
OLD | NEW |