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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 [_captureSession addInput:newInput]; | 299 [_captureSession addInput:newInput]; |
300 [self updateOrientation]; | 300 [self updateOrientation]; |
301 [_captureSession commitConfiguration]; | 301 [_captureSession commitConfiguration]; |
302 } | 302 } |
303 | 303 |
304 @end | 304 @end |
305 | 305 |
306 namespace webrtc { | 306 namespace webrtc { |
307 | 307 |
308 AVFoundationVideoCapturer::AVFoundationVideoCapturer() | 308 AVFoundationVideoCapturer::AVFoundationVideoCapturer() |
309 : _capturer(nil), _startThread(nullptr), _startTime(0) { | 309 : _capturer(nil), _startThread(nullptr) { |
310 // Set our supported formats. This matches kDefaultPreset. | 310 // Set our supported formats. This matches kDefaultPreset. |
311 std::vector<cricket::VideoFormat> supportedFormats; | 311 std::vector<cricket::VideoFormat> supportedFormats; |
312 supportedFormats.push_back(cricket::VideoFormat(kDefaultFormat)); | 312 supportedFormats.push_back(cricket::VideoFormat(kDefaultFormat)); |
313 SetSupportedFormats(supportedFormats); | 313 SetSupportedFormats(supportedFormats); |
314 _capturer = | 314 _capturer = |
315 [[RTCAVFoundationVideoCapturerInternal alloc] initWithCapturer:this]; | 315 [[RTCAVFoundationVideoCapturerInternal alloc] initWithCapturer:this]; |
316 } | 316 } |
317 | 317 |
318 AVFoundationVideoCapturer::~AVFoundationVideoCapturer() { | 318 AVFoundationVideoCapturer::~AVFoundationVideoCapturer() { |
319 _capturer = nil; | 319 _capturer = nil; |
(...skipping 17 matching lines...) Expand all Loading... |
337 // Keep track of which thread capture started on. This is the thread that | 337 // Keep track of which thread capture started on. This is the thread that |
338 // frames need to be sent to. | 338 // frames need to be sent to. |
339 RTC_DCHECK(!_startThread); | 339 RTC_DCHECK(!_startThread); |
340 _startThread = rtc::Thread::Current(); | 340 _startThread = rtc::Thread::Current(); |
341 | 341 |
342 SetCaptureFormat(&format); | 342 SetCaptureFormat(&format); |
343 // This isn't super accurate because it takes a while for the AVCaptureSession | 343 // This isn't super accurate because it takes a while for the AVCaptureSession |
344 // to spin up, and this call returns async. | 344 // to spin up, and this call returns async. |
345 // TODO(tkchin): make this better. | 345 // TODO(tkchin): make this better. |
346 [_capturer startCaptureAsync]; | 346 [_capturer startCaptureAsync]; |
347 _startTime = rtc::TimeNanos(); | |
348 SetCaptureState(cricket::CaptureState::CS_RUNNING); | 347 SetCaptureState(cricket::CaptureState::CS_RUNNING); |
349 | 348 |
350 return cricket::CaptureState::CS_STARTING; | 349 return cricket::CaptureState::CS_STARTING; |
351 } | 350 } |
352 | 351 |
353 void AVFoundationVideoCapturer::Stop() { | 352 void AVFoundationVideoCapturer::Stop() { |
354 [_capturer stopCaptureAsync]; | 353 [_capturer stopCaptureAsync]; |
355 SetCaptureFormat(NULL); | 354 SetCaptureFormat(NULL); |
356 _startThread = nullptr; | 355 _startThread = nullptr; |
357 } | 356 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 416 |
418 // Stuff data into a cricket::CapturedFrame. | 417 // Stuff data into a cricket::CapturedFrame. |
419 int64 currentTime = rtc::TimeNanos(); | 418 int64 currentTime = rtc::TimeNanos(); |
420 cricket::CapturedFrame frame; | 419 cricket::CapturedFrame frame; |
421 frame.width = yPlaneWidth; | 420 frame.width = yPlaneWidth; |
422 frame.height = yPlaneHeight; | 421 frame.height = yPlaneHeight; |
423 frame.pixel_width = 1; | 422 frame.pixel_width = 1; |
424 frame.pixel_height = 1; | 423 frame.pixel_height = 1; |
425 frame.fourcc = static_cast<uint32>(cricket::FOURCC_NV12); | 424 frame.fourcc = static_cast<uint32>(cricket::FOURCC_NV12); |
426 frame.time_stamp = currentTime; | 425 frame.time_stamp = currentTime; |
427 frame.elapsed_time = currentTime - _startTime; | |
428 frame.data = yPlaneAddress; | 426 frame.data = yPlaneAddress; |
429 frame.data_size = frameSize; | 427 frame.data_size = frameSize; |
430 | 428 |
431 if (_startThread->IsCurrent()) { | 429 if (_startThread->IsCurrent()) { |
432 SignalFrameCaptured(this, &frame); | 430 SignalFrameCaptured(this, &frame); |
433 } else { | 431 } else { |
434 _startThread->Invoke<void>( | 432 _startThread->Invoke<void>( |
435 rtc::Bind(&AVFoundationVideoCapturer::SignalFrameCapturedOnStartThread, | 433 rtc::Bind(&AVFoundationVideoCapturer::SignalFrameCapturedOnStartThread, |
436 this, &frame)); | 434 this, &frame)); |
437 } | 435 } |
438 CVPixelBufferUnlockBaseAddress(imageBuffer, lockFlags); | 436 CVPixelBufferUnlockBaseAddress(imageBuffer, lockFlags); |
439 } | 437 } |
440 | 438 |
441 void AVFoundationVideoCapturer::SignalFrameCapturedOnStartThread( | 439 void AVFoundationVideoCapturer::SignalFrameCapturedOnStartThread( |
442 const cricket::CapturedFrame* frame) { | 440 const cricket::CapturedFrame* frame) { |
443 RTC_DCHECK(_startThread->IsCurrent()); | 441 RTC_DCHECK(_startThread->IsCurrent()); |
444 // This will call a superclass method that will perform the frame conversion | 442 // This will call a superclass method that will perform the frame conversion |
445 // to I420. | 443 // to I420. |
446 SignalFrameCaptured(this, frame); | 444 SignalFrameCaptured(this, frame); |
447 } | 445 } |
448 | 446 |
449 } // namespace webrtc | 447 } // namespace webrtc |
OLD | NEW |