<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189913] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189913">189913</a></dd>
<dt>Author</dt> <dd>eric.carlson@apple.com</dd>
<dt>Date</dt> <dd>2015-09-17 08:33:29 -0700 (Thu, 17 Sep 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>[Mac MediaStream] Cleanup capture source classes
https://bugs.webkit.org/show_bug.cgi?id=149233
Reviewed by Jer Noble.
* platform/cf/CoreMediaSoftLink.cpp: Soft-link CMAudioFormatDescriptionGetStreamBasicDescription,
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer, and CMSampleBufferGetNumSamples.
* platform/cf/CoreMediaSoftLink.h:
* platform/mediastream/mac/AVAudioCaptureSource.h:
(WebCore::AVAudioCaptureSource::Observer::~Observer):
* platform/mediastream/mac/AVAudioCaptureSource.mm:
(WebCore::AVAudioCaptureSource::AVAudioCaptureSource): Initialize m_inputDescription.
(WebCore::AVAudioCaptureSource::capabilities): 0 -> nullptr.
(WebCore::AVAudioCaptureSource::addObserver): New, add an observer and tell it to prepare.
(WebCore::AVAudioCaptureSource::removeObserver): New.
(WebCore::operator==): Compare AudioStreamBasicDescription.
(WebCore::operator!=):
(WebCore::AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection): Call
observer->prepare when passed a new stream description, call observer->process.
* platform/mediastream/mac/AVCaptureDeviceManager.mm:
(WebCore::refreshCaptureDeviceList): Set m_groupID and m_localizedName.
(WebCore::AVCaptureDeviceManager::sessionSupportsConstraint): Invalid constraint names should
be ignored, so return true when passed one.
(WebCore::AVCaptureDeviceManager::getSourcesInfo): This just didn't work, fix it.
(WebCore::AVCaptureDeviceManager::verifyConstraintsForMediaType): Optional constraints are
optional so they don't need to be validated.
(WebCore::AVCaptureDeviceManager::bestSourcesForTypeAndConstraints): m_audioSource -> m_audioAVMediaCaptureSource,
m_videoSource -> m_videoAVMediaCaptureSource.
(WebCore::AVCaptureDeviceManager::sourceWithUID): Ditto.
* platform/mediastream/mac/AVMediaCaptureSource.h:
(WebCore::AVMediaCaptureSource::session):
(WebCore::AVMediaCaptureSource::device):
(WebCore::AVMediaCaptureSource::currentStates):
(WebCore::AVMediaCaptureSource::constraints):
(WebCore::AVMediaCaptureSource::statesDidChanged):
(WebCore::AVMediaCaptureSource::createWeakPtr):
(WebCore::AVMediaCaptureSource::buffer): Deleted.
(WebCore::AVMediaCaptureSource::setBuffer): Deleted.
* platform/mediastream/mac/AVMediaCaptureSource.mm:
(WebCore::AVMediaCaptureSource::AVMediaCaptureSource): Initilize m_weakPtrFactory.
(WebCore::AVMediaCaptureSource::scheduleDeferredTask): New, call a function asynchronously on
the main thread.
(-[WebCoreAVMediaCaptureSourceObserver captureOutput:didOutputSampleBuffer:fromConnection:]): Don't
dispatch calls to the main thread, let the derived classes do that if necessary.
* platform/mediastream/mac/AVVideoCaptureSource.h:
(WebCore::AVVideoCaptureSource::width):
(WebCore::AVVideoCaptureSource::height):
(WebCore::AVVideoCaptureSource::previewLayer):
(WebCore::AVVideoCaptureSource::currentFrameSampleBuffer):
* platform/mediastream/mac/AVVideoCaptureSource.mm:
(WebCore::AVVideoCaptureSource::setFrameRateConstraint): Remove unwanted logging.
(WebCore::AVVideoCaptureSource::setupCaptureSession): Configure the AVCaptureVideoDataOutput so
it delivers 32-bit BGRA samples.
(WebCore::AVVideoCaptureSource::calculateFramerate): Return bool to signal if the frame rate
changed.
(WebCore::AVVideoCaptureSource::processNewFrame): New. Process sample buffer, invalidate cached
image, signal when characteristics change.
(WebCore::AVVideoCaptureSource::captureOutputDidOutputSampleBufferFromConnection): Schedule
call to processNewFrame on the main thread so we do all video processing on main thread.
(WebCore::AVVideoCaptureSource::currentFrameImage): Create and return a CVImageBuffer of the
current video frame.
(WebCore::AVVideoCaptureSource::paintCurrentFrameInContext): Draw the current frame to a context.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformcfCoreMediaSoftLinkcpp">trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformcfCoreMediaSoftLinkh">trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourceh">trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourcemm">trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVCaptureDeviceManagermm">trunk/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVMediaCaptureSourceh">trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVMediaCaptureSourcemm">trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVVideoCaptureSourceh">trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmediastreammacAVVideoCaptureSourcemm">trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/ChangeLog        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -1,3 +1,72 @@
</span><ins>+2015-09-17 Eric Carlson <eric.carlson@apple.com>
+
+ [Mac MediaStream] Cleanup capture source classes
+ https://bugs.webkit.org/show_bug.cgi?id=149233
+
+ Reviewed by Jer Noble.
+
+ * platform/cf/CoreMediaSoftLink.cpp: Soft-link CMAudioFormatDescriptionGetStreamBasicDescription,
+ CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer, and CMSampleBufferGetNumSamples.
+ * platform/cf/CoreMediaSoftLink.h:
+
+ * platform/mediastream/mac/AVAudioCaptureSource.h:
+ (WebCore::AVAudioCaptureSource::Observer::~Observer):
+ * platform/mediastream/mac/AVAudioCaptureSource.mm:
+ (WebCore::AVAudioCaptureSource::AVAudioCaptureSource): Initialize m_inputDescription.
+ (WebCore::AVAudioCaptureSource::capabilities): 0 -> nullptr.
+ (WebCore::AVAudioCaptureSource::addObserver): New, add an observer and tell it to prepare.
+ (WebCore::AVAudioCaptureSource::removeObserver): New.
+ (WebCore::operator==): Compare AudioStreamBasicDescription.
+ (WebCore::operator!=):
+ (WebCore::AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection): Call
+ observer->prepare when passed a new stream description, call observer->process.
+
+ * platform/mediastream/mac/AVCaptureDeviceManager.mm:
+ (WebCore::refreshCaptureDeviceList): Set m_groupID and m_localizedName.
+ (WebCore::AVCaptureDeviceManager::sessionSupportsConstraint): Invalid constraint names should
+ be ignored, so return true when passed one.
+ (WebCore::AVCaptureDeviceManager::getSourcesInfo): This just didn't work, fix it.
+ (WebCore::AVCaptureDeviceManager::verifyConstraintsForMediaType): Optional constraints are
+ optional so they don't need to be validated.
+ (WebCore::AVCaptureDeviceManager::bestSourcesForTypeAndConstraints): m_audioSource -> m_audioAVMediaCaptureSource,
+ m_videoSource -> m_videoAVMediaCaptureSource.
+ (WebCore::AVCaptureDeviceManager::sourceWithUID): Ditto.
+
+ * platform/mediastream/mac/AVMediaCaptureSource.h:
+ (WebCore::AVMediaCaptureSource::session):
+ (WebCore::AVMediaCaptureSource::device):
+ (WebCore::AVMediaCaptureSource::currentStates):
+ (WebCore::AVMediaCaptureSource::constraints):
+ (WebCore::AVMediaCaptureSource::statesDidChanged):
+ (WebCore::AVMediaCaptureSource::createWeakPtr):
+ (WebCore::AVMediaCaptureSource::buffer): Deleted.
+ (WebCore::AVMediaCaptureSource::setBuffer): Deleted.
+ * platform/mediastream/mac/AVMediaCaptureSource.mm:
+ (WebCore::AVMediaCaptureSource::AVMediaCaptureSource): Initilize m_weakPtrFactory.
+ (WebCore::AVMediaCaptureSource::scheduleDeferredTask): New, call a function asynchronously on
+ the main thread.
+ (-[WebCoreAVMediaCaptureSourceObserver captureOutput:didOutputSampleBuffer:fromConnection:]): Don't
+ dispatch calls to the main thread, let the derived classes do that if necessary.
+
+ * platform/mediastream/mac/AVVideoCaptureSource.h:
+ (WebCore::AVVideoCaptureSource::width):
+ (WebCore::AVVideoCaptureSource::height):
+ (WebCore::AVVideoCaptureSource::previewLayer):
+ (WebCore::AVVideoCaptureSource::currentFrameSampleBuffer):
+ * platform/mediastream/mac/AVVideoCaptureSource.mm:
+ (WebCore::AVVideoCaptureSource::setFrameRateConstraint): Remove unwanted logging.
+ (WebCore::AVVideoCaptureSource::setupCaptureSession): Configure the AVCaptureVideoDataOutput so
+ it delivers 32-bit BGRA samples.
+ (WebCore::AVVideoCaptureSource::calculateFramerate): Return bool to signal if the frame rate
+ changed.
+ (WebCore::AVVideoCaptureSource::processNewFrame): New. Process sample buffer, invalidate cached
+ image, signal when characteristics change.
+ (WebCore::AVVideoCaptureSource::captureOutputDidOutputSampleBufferFromConnection): Schedule
+ call to processNewFrame on the main thread so we do all video processing on main thread.
+ (WebCore::AVVideoCaptureSource::currentFrameImage): Create and return a CVImageBuffer of the
+ current video frame.
+ (WebCore::AVVideoCaptureSource::paintCurrentFrameInContext): Draw the current frame to a context.
+
</ins><span class="cx"> 2015-09-15 Sergio Villar Senin <svillar@igalia.com>
</span><span class="cx">
</span><span class="cx"> [CSS Grid Layout] Using automatic (instead of min-content) minimums for 'auto' tracks
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcfCoreMediaSoftLinkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.cpp        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -101,6 +101,9 @@
</span><span class="cx"> SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, CoreMedia, kCMSampleBufferAttachmentKey_ResetDecoderBeforeDecoding, CFStringRef)
</span><span class="cx"> SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, CoreMedia, kCMTimebaseNotification_EffectiveRateChanged, CFStringRef)
</span><span class="cx"> SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, CoreMedia, kCMTimebaseNotification_TimeJumped, CFStringRef)
</span><ins>+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMAudioFormatDescriptionGetStreamBasicDescription, const AudioStreamBasicDescription *, (CMAudioFormatDescriptionRef desc), (desc))
+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer, OSStatus, (CMSampleBufferRef sbuf, size_t *bufferListSizeNeededOut, AudioBufferList *bufferListOut, size_t bufferListSize, CFAllocatorRef bbufStructAllocator, CFAllocatorRef bbufMemoryAllocator, uint32_t flags, CMBlockBufferRef *blockBufferOut), (sbuf, bufferListSizeNeededOut, bufferListOut, bufferListSize, bbufStructAllocator, bbufMemoryAllocator, flags, blockBufferOut))
+SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, CoreMedia, CMSampleBufferGetNumSamples, CMItemCount, (CMSampleBufferRef sbuf), (sbuf))
</ins><span class="cx"> #endif // PLATFORM(COCOA)
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcfCoreMediaSoftLinkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/cf/CoreMediaSoftLink.h        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -168,6 +168,12 @@
</span><span class="cx"> #define kCMTimebaseNotification_EffectiveRateChanged get_CoreMedia_kCMTimebaseNotification_EffectiveRateChanged()
</span><span class="cx"> SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, CoreMedia, kCMTimebaseNotification_TimeJumped, CFStringRef)
</span><span class="cx"> #define kCMTimebaseNotification_TimeJumped get_CoreMedia_kCMTimebaseNotification_TimeJumped()
</span><ins>+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMAudioFormatDescriptionGetStreamBasicDescription, const AudioStreamBasicDescription *, (CMAudioFormatDescriptionRef desc), (desc))
+#define CMAudioFormatDescriptionGetStreamBasicDescription softLink_CoreMedia_CMAudioFormatDescriptionGetStreamBasicDescription
+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer, OSStatus, (CMSampleBufferRef sbuf, size_t *bufferListSizeNeededOut, AudioBufferList *bufferListOut, size_t bufferListSize, CFAllocatorRef bbufStructAllocator, CFAllocatorRef bbufMemoryAllocator, uint32_t flags, CMBlockBufferRef *blockBufferOut), (sbuf, bufferListSizeNeededOut, bufferListOut, bufferListSize, bbufStructAllocator, bbufMemoryAllocator, flags, blockBufferOut))
+#define CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer softLink_CoreMedia_CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer
+SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, CoreMedia, CMSampleBufferGetNumSamples, CMItemCount, (CMSampleBufferRef sbuf), (sbuf))
+#define CMSampleBufferGetNumSamples softLink_CoreMedia_CMSampleBufferGetNumSamples
</ins><span class="cx">
</span><span class="cx"> #endif // PLATFORM(COCOA)
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.h        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -29,27 +29,44 @@
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
</span><span class="cx">
</span><span class="cx"> #include "AVMediaCaptureSource.h"
</span><ins>+#include <wtf/Lock.h>
</ins><span class="cx">
</span><ins>+typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
</ins><span class="cx"> typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><del>-
</del><ins>+
</ins><span class="cx"> class AVAudioCaptureSource : public AVMediaCaptureSource {
</span><span class="cx"> public:
</span><ins>+
+ class Observer {
+ public:
+ virtual ~Observer() { }
+ virtual void prepare(const AudioStreamBasicDescription *) = 0;
+ virtual void unprepare() = 0;
+ virtual void process(CMFormatDescriptionRef, CMSampleBufferRef) = 0;
+ };
+
</ins><span class="cx"> static RefPtr<AVMediaCaptureSource> create(AVCaptureDevice*, const AtomicString&, PassRefPtr<MediaConstraints>);
</span><del>-
</del><ins>+
+ void addObserver(Observer*);
+ void removeObserver(Observer*);
+
</ins><span class="cx"> private:
</span><span class="cx"> AVAudioCaptureSource(AVCaptureDevice*, const AtomicString&, PassRefPtr<MediaConstraints>);
</span><span class="cx"> virtual ~AVAudioCaptureSource();
</span><span class="cx">
</span><del>- virtual RefPtr<RealtimeMediaSourceCapabilities> capabilities() const override;
- virtual void captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutput*, CMSampleBufferRef, AVCaptureConnection*) override;
</del><ins>+ RefPtr<RealtimeMediaSourceCapabilities> capabilities() const override;
+ void captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutput*, CMSampleBufferRef, AVCaptureConnection*) override;
</ins><span class="cx">
</span><del>- virtual void setupCaptureSession() override;
- virtual void updateStates() override;
-
</del><ins>+ void setupCaptureSession() override;
+ void updateStates() override;
+
</ins><span class="cx"> RetainPtr<AVCaptureConnection> m_audioConnection;
</span><del>- RetainPtr<CMFormatDescriptionRef> m_audioFormatDescription;
</del><ins>+
+ std::unique_ptr<AudioStreamBasicDescription> m_inputDescription;
+ Vector<Observer*> m_observers;
+ Lock m_lock;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVAudioCaptureSourcemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVAudioCaptureSource.mm        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -24,20 +24,21 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> #import "config.h"
</span><ins>+#import "AVAudioCaptureSource.h"
</ins><span class="cx">
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
</span><span class="cx">
</span><del>-#import "AVAudioCaptureSource.h"
-
-#import "CoreMediaSoftLink.h"
</del><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "MediaConstraints.h"
</span><span class="cx"> #import "NotImplemented.h"
</span><span class="cx"> #import "RealtimeMediaSourceStates.h"
</span><span class="cx"> #import "SoftLinking.h"
</span><span class="cx"> #import <AVFoundation/AVFoundation.h>
</span><del>-#import <objc/runtime.h>
</del><ins>+#import <CoreAudio/CoreAudioTypes.h>
+#import <wtf/HashSet.h>
</ins><span class="cx">
</span><ins>+#import "CoreMediaSoftLink.h"
+
</ins><span class="cx"> typedef AVCaptureConnection AVCaptureConnectionType;
</span><span class="cx"> typedef AVCaptureDevice AVCaptureDeviceType;
</span><span class="cx"> typedef AVCaptureDeviceInput AVCaptureDeviceInputType;
</span><span class="lines">@@ -68,6 +69,7 @@
</span><span class="cx"> {
</span><span class="cx"> currentStates()->setSourceId(id);
</span><span class="cx"> currentStates()->setSourceType(RealtimeMediaSourceStates::Microphone);
</span><ins>+ m_inputDescription = std::make_unique<AudioStreamBasicDescription>();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> AVAudioCaptureSource::~AVAudioCaptureSource()
</span><span class="lines">@@ -77,7 +79,7 @@
</span><span class="cx"> RefPtr<RealtimeMediaSourceCapabilities> AVAudioCaptureSource::capabilities() const
</span><span class="cx"> {
</span><span class="cx"> notImplemented();
</span><del>- return 0;
</del><ins>+ return nullptr;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void AVAudioCaptureSource::updateStates()
</span><span class="lines">@@ -85,6 +87,25 @@
</span><span class="cx"> // FIXME: use [AVCaptureAudioPreviewOutput volume] for volume
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void AVAudioCaptureSource::addObserver(AVAudioCaptureSource::Observer* observer)
+{
+ {
+ LockHolder lock(m_lock);
+ m_observers.append(observer);
+ }
+
+ if (m_inputDescription->mSampleRate)
+ observer->prepare(m_inputDescription.get());
+}
+
+void AVAudioCaptureSource::removeObserver(AVAudioCaptureSource::Observer* observer)
+{
+ LockHolder lock(m_lock);
+ size_t pos = m_observers.find(observer);
+ if (pos != notFound)
+ m_observers.remove(pos);
+}
+
</ins><span class="cx"> void AVAudioCaptureSource::setupCaptureSession()
</span><span class="cx"> {
</span><span class="cx"> RetainPtr<AVCaptureDeviceInputType> audioIn = adoptNS([allocAVCaptureDeviceInputInstance() initWithDevice:device() error:nil]);
</span><span class="lines">@@ -100,14 +121,47 @@
</span><span class="cx"> m_audioConnection = adoptNS([audioOutput.get() connectionWithMediaType:AVMediaTypeAudio]);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool operator==(const AudioStreamBasicDescription& a, const AudioStreamBasicDescription& b)
+{
+ return a.mSampleRate == b.mSampleRate
+ && a.mFormatID == b.mFormatID
+ && a.mFormatFlags == b.mFormatFlags
+ && a.mBytesPerPacket == b.mBytesPerPacket
+ && a.mFramesPerPacket == b.mFramesPerPacket
+ && a.mBytesPerFrame == b.mBytesPerFrame
+ && a.mChannelsPerFrame == b.mChannelsPerFrame
+ && a.mBitsPerChannel == b.mBitsPerChannel;
+}
+
+static bool operator!=(const AudioStreamBasicDescription& a, const AudioStreamBasicDescription& b)
+{
+ return !(a == b);
+}
+
</ins><span class="cx"> void AVAudioCaptureSource::captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutputType*, CMSampleBufferRef sampleBuffer, AVCaptureConnectionType*)
</span><span class="cx"> {
</span><ins>+ Vector<Observer*> observers;
+ {
+ LockHolder lock(m_lock);
+ if (m_observers.isEmpty())
+ return;
+
+ copyToVector(m_observers, observers);
+ }
+
</ins><span class="cx"> CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
</span><span class="cx"> if (!formatDescription)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- CFRetain(formatDescription);
- m_audioFormatDescription = adoptCF(formatDescription);
</del><ins>+ const AudioStreamBasicDescription* streamDescription = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);
+ if (*m_inputDescription != *streamDescription) {
+ m_inputDescription = std::make_unique<AudioStreamBasicDescription>(*streamDescription);
+ for (auto& observer : observers)
+ observer->prepare(m_inputDescription.get());
+ }
+
+ for (auto& observer : observers)
+ observer->process(formatDescription, sampleBuffer);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVCaptureDeviceManagermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVCaptureDeviceManager.mm        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -24,14 +24,14 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> #import "config.h"
</span><ins>+#import "AVCaptureDeviceManager.h"
</ins><span class="cx">
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
</span><span class="cx">
</span><del>-#import "AVCaptureDeviceManager.h"
-
</del><span class="cx"> #import "AVAudioCaptureSource.h"
</span><span class="cx"> #import "AVMediaCaptureSource.h"
</span><span class="cx"> #import "AVVideoCaptureSource.h"
</span><ins>+#import "AudioSourceProvider.h"
</ins><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "MediaConstraints.h"
</span><span class="cx"> #import "RealtimeMediaSource.h"
</span><span class="lines">@@ -99,12 +99,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> String m_captureDeviceID;
</span><ins>+ String m_localizedName;
+ String m_groupID;
</ins><span class="cx">
</span><span class="cx"> String m_audioSourceId;
</span><del>- RefPtr<AVMediaCaptureSource> m_audioSource;
</del><ins>+ RefPtr<AVMediaCaptureSource> m_audioAVMediaCaptureSource;
</ins><span class="cx">
</span><span class="cx"> String m_videoSourceId;
</span><del>- RefPtr<AVMediaCaptureSource> m_videoSource;
</del><ins>+ RefPtr<AVMediaCaptureSource> m_videoAVMediaCaptureSource;
</ins><span class="cx">
</span><span class="cx"> bool m_enabled;
</span><span class="cx"> };
</span><span class="lines">@@ -158,6 +160,9 @@
</span><span class="cx"> if ([device hasMediaType:AVMediaTypeVideo] || [device hasMediaType:AVMediaTypeMuxed])
</span><span class="cx"> source.m_videoSourceId = createCanonicalUUIDString();
</span><span class="cx">
</span><ins>+ source.m_groupID = createCanonicalUUIDString();
+ source.m_localizedName = device.localizedName;
+
</ins><span class="cx"> devices.append(source);
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="lines">@@ -258,7 +263,7 @@
</span><span class="cx"> {
</span><span class="cx"> size_t constraint = validConstraintNames().find(name);
</span><span class="cx"> if (constraint == notFound)
</span><del>- return false;
</del><ins>+ return true;
</ins><span class="cx">
</span><span class="cx"> switch (constraint) {
</span><span class="cx"> case Width:
</span><span class="lines">@@ -322,20 +327,17 @@
</span><span class="cx"> return sourcesInfo;
</span><span class="cx">
</span><span class="cx"> Vector<CaptureDevice>& devices = captureDeviceList();
</span><del>- size_t count = devices.size();
- for (size_t i = 0; i < count; ++i) {
- AVCaptureDeviceType *device = [AVCaptureDevice deviceWithUniqueID:devices[i].m_captureDeviceID];
- ASSERT(device);
</del><ins>+ for (auto captureDevice : devices) {
</ins><span class="cx">
</span><del>- if (!devices[i].m_enabled)
</del><ins>+ if (!captureDevice.m_enabled)
</ins><span class="cx"> continue;
</span><del>- // FIXME: Change groupID from localizedName to something more meaningful
- if (devices[i].m_videoSource)
- sourcesInfo.append(TrackSourceInfo::create(devices[i].m_videoSourceId, TrackSourceInfo::Video, device.localizedName, device.localizedName, devices[i].m_captureDeviceID));
- if (devices[i].m_audioSource)
- sourcesInfo.append(TrackSourceInfo::create(devices[i].m_audioSourceId, TrackSourceInfo::Audio, device.localizedName, device.localizedName, devices[i].m_captureDeviceID));
</del><ins>+
+ if (!captureDevice.m_videoSourceId.isEmpty())
+ sourcesInfo.append(TrackSourceInfo::create(captureDevice.m_videoSourceId, TrackSourceInfo::Video, captureDevice.m_localizedName, captureDevice.m_groupID, captureDevice.m_captureDeviceID));
+ if (!captureDevice.m_audioSourceId.isEmpty())
+ sourcesInfo.append(TrackSourceInfo::create(captureDevice.m_audioSourceId, TrackSourceInfo::Audio, captureDevice.m_localizedName, captureDevice.m_groupID, captureDevice.m_captureDeviceID));
</ins><span class="cx"> }
</span><del>-
</del><ins>+
</ins><span class="cx"> LOG(Media, "AVCaptureDeviceManager::getSourcesInfo(%p), found %d active devices", this, sourcesInfo.size());
</span><span class="cx">
</span><span class="cx"> return sourcesInfo;
</span><span class="lines">@@ -352,6 +354,8 @@
</span><span class="cx"> Vector<MediaConstraint> mandatoryConstraints;
</span><span class="cx"> constraints->getMandatoryConstraints(mandatoryConstraints);
</span><span class="cx"> if (mandatoryConstraints.size()) {
</span><ins>+
+ // FIXME: this method should take an AVCaptureDevice and use its AVCaptureSession instead of creating a new one.
</ins><span class="cx"> RetainPtr<AVCaptureSessionType> session = adoptNS([allocAVCaptureSessionInstance() init]);
</span><span class="cx"> for (size_t i = 0; i < mandatoryConstraints.size(); ++i) {
</span><span class="cx"> const MediaConstraint& constraint = mandatoryConstraints[i];
</span><span class="lines">@@ -361,20 +365,7 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span><del>-
- Vector<MediaConstraint> optionalConstraints;
- constraints->getOptionalConstraints(optionalConstraints);
- if (!optionalConstraints.size())
- return true;
</del><span class="cx">
</span><del>- for (size_t i = 0; i < optionalConstraints.size(); ++i) {
- const MediaConstraint& constraint = optionalConstraints[i];
- if (!isValidConstraint(type, constraint.m_name)) {
- invalidConstraint = constraint.m_name;
- return false;
- }
- }
-
</del><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -392,28 +383,30 @@
</span><span class="cx"> }
</span><span class="cx"> } sortBasedOffFitnessScore;
</span><span class="cx">
</span><del>- for (auto& captureDevice : captureDeviceList()) {
</del><ins>+ Vector<CaptureDevice>& devices = captureDeviceList();
+
+ for (auto& captureDevice : devices) {
</ins><span class="cx"> if (!captureDevice.m_enabled)
</span><span class="cx"> continue;
</span><span class="cx">
</span><span class="cx"> // FIXME: consider the constraints when choosing among multiple devices. For now just select the first available
</span><span class="cx"> // device of the appropriate type.
</span><span class="cx"> if (type == RealtimeMediaSource::Audio && !captureDevice.m_audioSourceId.isEmpty()) {
</span><del>- if (!captureDevice.m_audioSource) {
</del><ins>+ if (!captureDevice.m_audioAVMediaCaptureSource) {
</ins><span class="cx"> AVCaptureDeviceType *device = [AVCaptureDevice deviceWithUniqueID:captureDevice.m_captureDeviceID];
</span><span class="cx"> ASSERT(device);
</span><del>- captureDevice.m_audioSource = AVAudioCaptureSource::create(device, captureDevice.m_audioSourceId, constraints);
</del><ins>+ captureDevice.m_audioAVMediaCaptureSource = AVAudioCaptureSource::create(device, captureDevice.m_audioSourceId, constraints);
</ins><span class="cx"> }
</span><del>- bestSourcesList.append(captureDevice.m_audioSource);
</del><ins>+ bestSourcesList.append(captureDevice.m_audioAVMediaCaptureSource);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (type == RealtimeMediaSource::Video && !captureDevice.m_videoSourceId.isEmpty()) {
</span><del>- if (!captureDevice.m_videoSource) {
</del><ins>+ if (!captureDevice.m_videoAVMediaCaptureSource) {
</ins><span class="cx"> AVCaptureDeviceType *device = [AVCaptureDevice deviceWithUniqueID:captureDevice.m_captureDeviceID];
</span><span class="cx"> ASSERT(device);
</span><del>- captureDevice.m_videoSource = AVVideoCaptureSource::create(device, captureDevice.m_videoSourceId, constraints);
</del><ins>+ captureDevice.m_videoAVMediaCaptureSource = AVVideoCaptureSource::create(device, captureDevice.m_videoSourceId, constraints);
</ins><span class="cx"> }
</span><del>- bestSourcesList.append(captureDevice.m_videoSource);
</del><ins>+ bestSourcesList.append(captureDevice.m_videoAVMediaCaptureSource);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> std::sort(bestSourcesList.begin(), bestSourcesList.end(), sortBasedOffFitnessScore);
</span><span class="lines">@@ -442,12 +435,14 @@
</span><span class="cx"> AVCaptureDeviceType *device = [AVCaptureDevice deviceWithUniqueID:captureDevice.m_captureDeviceID];
</span><span class="cx"> ASSERT(device);
</span><span class="cx"> if (type == RealtimeMediaSource::Type::Audio && !captureDevice.m_audioSourceId.isEmpty()) {
</span><del>- captureDevice.m_audioSource = AVAudioCaptureSource::create(device, captureDevice.m_audioSourceId, constraints);
- return captureDevice.m_audioSource;
</del><ins>+ if (!captureDevice.m_audioAVMediaCaptureSource)
+ captureDevice.m_audioAVMediaCaptureSource = AVAudioCaptureSource::create(device, captureDevice.m_audioSourceId, constraints);
+ return captureDevice.m_audioAVMediaCaptureSource;
</ins><span class="cx"> }
</span><span class="cx"> if (type == RealtimeMediaSource::Type::Video && !captureDevice.m_videoSourceId.isEmpty()) {
</span><del>- captureDevice.m_videoSource = AVVideoCaptureSource::create(device, captureDevice.m_videoSourceId, constraints);
- return captureDevice.m_videoSource;
</del><ins>+ if (!captureDevice.m_videoAVMediaCaptureSource)
+ captureDevice.m_videoAVMediaCaptureSource = AVVideoCaptureSource::create(device, captureDevice.m_videoSourceId, constraints);
+ return captureDevice.m_videoAVMediaCaptureSource;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVMediaCaptureSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.h (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.h        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.h        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,8 +28,11 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
</span><span class="cx">
</span><ins>+#include "GenericTaskQueue.h"
</ins><span class="cx"> #include "RealtimeMediaSource.h"
</span><ins>+#include "Timer.h"
</ins><span class="cx"> #include <wtf/RetainPtr.h>
</span><ins>+#include <wtf/WeakPtr.h>
</ins><span class="cx">
</span><span class="cx"> OBJC_CLASS AVCaptureAudioDataOutput;
</span><span class="cx"> OBJC_CLASS AVCaptureConnection;
</span><span class="lines">@@ -53,36 +56,38 @@
</span><span class="cx">
</span><span class="cx"> AVCaptureSession *session() const { return m_session.get(); }
</span><span class="cx">
</span><ins>+ void startProducingData() override;
+ void stopProducingData() override;
+
</ins><span class="cx"> protected:
</span><span class="cx"> AVMediaCaptureSource(AVCaptureDevice*, const AtomicString&, RealtimeMediaSource::Type, PassRefPtr<MediaConstraints>);
</span><span class="cx">
</span><del>- virtual const RealtimeMediaSourceStates& states() override;
</del><ins>+ const RealtimeMediaSourceStates& states() override;
</ins><span class="cx">
</span><del>- virtual void startProducingData() override;
- virtual void stopProducingData() override;
-
</del><span class="cx"> virtual void setupCaptureSession() = 0;
</span><span class="cx"> virtual void updateStates() = 0;
</span><span class="cx">
</span><span class="cx"> AVCaptureDevice *device() const { return m_device.get(); }
</span><span class="cx"> RealtimeMediaSourceStates* currentStates() { return &m_currentStates; }
</span><span class="cx"> MediaConstraints* constraints() { return m_constraints.get(); }
</span><del>- CMSampleBufferRef buffer() const { return m_buffer.get(); }
</del><span class="cx">
</span><span class="cx"> void setVideoSampleBufferDelegate(AVCaptureVideoDataOutput*);
</span><span class="cx"> void setAudioSampleBufferDelegate(AVCaptureAudioDataOutput*);
</span><ins>+
+ void scheduleDeferredTask(std::function<void ()>);
+
+ void statesDidChanged() { }
</ins><span class="cx">
</span><del>- void setBuffer(CMSampleBufferRef buffer) { m_buffer = buffer; }
-
</del><span class="cx"> private:
</span><span class="cx"> void setupSession();
</span><ins>+ WeakPtr<AVMediaCaptureSource> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
</ins><span class="cx">
</span><ins>+ WeakPtrFactory<AVMediaCaptureSource> m_weakPtrFactory;
</ins><span class="cx"> RetainPtr<WebCoreAVMediaCaptureSourceObserver> m_objcObserver;
</span><span class="cx"> RefPtr<MediaConstraints> m_constraints;
</span><span class="cx"> RealtimeMediaSourceStates m_currentStates;
</span><span class="cx"> RetainPtr<AVCaptureSession> m_session;
</span><span class="cx"> RetainPtr<AVCaptureDevice> m_device;
</span><del>- RetainPtr<CMSampleBufferRef> m_buffer;
</del><span class="cx">
</span><span class="cx"> bool m_isRunning;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVMediaCaptureSourcemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVMediaCaptureSource.mm        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -24,11 +24,11 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> #import "config.h"
</span><ins>+#import "AVMediaCaptureSource.h"
</ins><span class="cx">
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
</span><span class="cx">
</span><del>-#import "AVMediaCaptureSource.h"
-
</del><ins>+#import "AudioSourceProvider.h"
</ins><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "MediaConstraints.h"
</span><span class="cx"> #import "RealtimeMediaSourceStates.h"
</span><span class="lines">@@ -123,12 +123,13 @@
</span><span class="cx">
</span><span class="cx"> AVMediaCaptureSource::AVMediaCaptureSource(AVCaptureDeviceType* device, const AtomicString& id, RealtimeMediaSource::Type type, PassRefPtr<MediaConstraints> constraints)
</span><span class="cx"> : RealtimeMediaSource(id, type, emptyString())
</span><ins>+ , m_weakPtrFactory(this)
</ins><span class="cx"> , m_objcObserver(adoptNS([[WebCoreAVMediaCaptureSourceObserver alloc] initWithCallback:this]))
</span><span class="cx"> , m_constraints(constraints)
</span><span class="cx"> , m_device(device)
</span><span class="cx"> , m_isRunning(false)
</span><span class="cx"> {
</span><del>- setName([device localizedName]);
</del><ins>+ setName(device.localizedName);
</ins><span class="cx"> m_currentStates.setSourceType(type == RealtimeMediaSource::Video ? RealtimeMediaSourceStates::Camera : RealtimeMediaSourceStates::Microphone);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -195,6 +196,19 @@
</span><span class="cx"> [audioOutput setSampleBufferDelegate:m_objcObserver.get() queue:globaAudioCaptureSerialQueue()];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void AVMediaCaptureSource::scheduleDeferredTask(std::function<void ()> function)
+{
+ ASSERT(function);
+
+ auto weakThis = createWeakPtr();
+ callOnMainThread([weakThis, function] {
+ if (!weakThis)
+ return;
+
+ function();
+ });
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span><span class="cx"> @implementation WebCoreAVMediaCaptureSourceObserver
</span><span class="lines">@@ -232,12 +246,7 @@
</span><span class="cx"> if (!m_callback)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- CFRetain(sampleBuffer);
- dispatch_async(dispatch_get_main_queue(), ^{
- if (m_callback)
- m_callback->captureOutputDidOutputSampleBufferFromConnection(captureOutput, sampleBuffer, connection);
- CFRelease(sampleBuffer);
- });
</del><ins>+ m_callback->captureOutputDidOutputSampleBufferFromConnection(captureOutput, sampleBuffer, connection);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVVideoCaptureSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.h        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -32,37 +32,48 @@
</span><span class="cx">
</span><span class="cx"> OBJC_CLASS AVCaptureVideoPreviewLayer;
</span><span class="cx">
</span><ins>+typedef struct CGImage *CGImageRef;
</ins><span class="cx"> typedef const struct opaqueCMFormatDescription *CMFormatDescriptionRef;
</span><ins>+typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><ins>+class FloatRect;
+class GraphicsContext;
+
</ins><span class="cx"> class AVVideoCaptureSource : public AVMediaCaptureSource {
</span><span class="cx"> public:
</span><span class="cx"> static RefPtr<AVMediaCaptureSource> create(AVCaptureDevice*, const AtomicString&, PassRefPtr<MediaConstraints>);
</span><span class="cx">
</span><del>- virtual RefPtr<RealtimeMediaSourceCapabilities> capabilities() const override;
- virtual void captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutput*, CMSampleBufferRef, AVCaptureConnection*) override;
-
- virtual int32_t width() const { return m_width; }
- virtual int32_t height() const { return m_height; }
</del><ins>+ int32_t width() const { return m_width; }
+ int32_t height() const { return m_height; }
</ins><span class="cx">
</span><span class="cx"> AVCaptureVideoPreviewLayer* previewLayer() { return m_videoPreviewLayer.get(); }
</span><del>-
</del><ins>+ CMSampleBufferRef currentFrameSampleBuffer() const { return m_buffer.get(); }
+ void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&);
+ RetainPtr<CGImageRef> currentFrameImage();
+
</ins><span class="cx"> private:
</span><span class="cx"> AVVideoCaptureSource(AVCaptureDevice*, const AtomicString&, PassRefPtr<MediaConstraints>);
</span><span class="cx"> virtual ~AVVideoCaptureSource();
</span><span class="cx">
</span><del>- virtual void setupCaptureSession() override;
- virtual void updateStates() override;
</del><ins>+ void setupCaptureSession() override;
+ void updateStates() override;
</ins><span class="cx">
</span><ins>+ RefPtr<RealtimeMediaSourceCapabilities> capabilities() const override;
+
</ins><span class="cx"> bool applyConstraints(MediaConstraints*);
</span><span class="cx"> bool setFrameRateConstraint(float minFrameRate, float maxFrameRate);
</span><span class="cx">
</span><del>- void calculateFramerate(CMSampleBufferRef);
</del><ins>+ bool calculateFramerate(CMSampleBufferRef);
</ins><span class="cx">
</span><ins>+ void captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutput*, CMSampleBufferRef, AVCaptureConnection*) override;
+ void processNewFrame(RetainPtr<CMSampleBufferRef>);
+
</ins><span class="cx"> RetainPtr<AVCaptureConnection> m_videoConnection;
</span><del>- RetainPtr<CMFormatDescriptionRef> m_videoFormatDescription;
</del><span class="cx"> RetainPtr<AVCaptureVideoPreviewLayer> m_videoPreviewLayer;
</span><ins>+ RetainPtr<CMSampleBufferRef> m_buffer;
+ RetainPtr<CGImageRef> m_lastImage;
</ins><span class="cx"> Vector<Float64> m_videoFrameTimeStamps;
</span><span class="cx"> Float64 m_frameRate;
</span><span class="cx"> int32_t m_width;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmediastreammacAVVideoCaptureSourcemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm (189912 => 189913)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm        2015-09-17 13:00:48 UTC (rev 189912)
+++ trunk/Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm        2015-09-17 15:33:29 UTC (rev 189913)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -24,13 +24,14 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> #import "config.h"
</span><ins>+#import "AVVideoCaptureSource.h"
</ins><span class="cx">
</span><span class="cx"> #if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
</span><span class="cx">
</span><del>-#import "AVVideoCaptureSource.h"
-
</del><span class="cx"> #import "AVCaptureDeviceManager.h"
</span><span class="cx"> #import "BlockExceptions.h"
</span><ins>+#import "GraphicsContextCG.h"
+#import "IntRect.h"
</ins><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "MediaConstraints.h"
</span><span class="cx"> #import "NotImplemented.h"
</span><span class="lines">@@ -48,6 +49,7 @@
</span><span class="cx"> typedef AVCaptureVideoPreviewLayer AVCaptureVideoPreviewLayerType;
</span><span class="cx">
</span><span class="cx"> SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
</span><ins>+SOFT_LINK_FRAMEWORK_OPTIONAL(CoreVideo)
</ins><span class="cx">
</span><span class="cx"> SOFT_LINK_CLASS(AVFoundation, AVCaptureConnection)
</span><span class="cx"> SOFT_LINK_CLASS(AVFoundation, AVCaptureDevice)
</span><span class="lines">@@ -76,6 +78,17 @@
</span><span class="cx"> #define AVCaptureSessionPreset352x288 getAVCaptureSessionPreset352x288()
</span><span class="cx"> #define AVCaptureSessionPresetLow getAVCaptureSessionPresetLow()
</span><span class="cx">
</span><ins>+SOFT_LINK(CoreVideo, CVPixelBufferGetWidth, size_t, (CVPixelBufferRef pixelBuffer), (pixelBuffer))
+SOFT_LINK(CoreVideo, CVPixelBufferGetHeight, size_t, (CVPixelBufferRef pixelBuffer), (pixelBuffer))
+SOFT_LINK(CoreVideo, CVPixelBufferGetBaseAddress, void*, (CVPixelBufferRef pixelBuffer), (pixelBuffer))
+SOFT_LINK(CoreVideo, CVPixelBufferGetBytesPerRow, size_t, (CVPixelBufferRef pixelBuffer), (pixelBuffer))
+SOFT_LINK(CoreVideo, CVPixelBufferGetPixelFormatType, OSType, (CVPixelBufferRef pixelBuffer), (pixelBuffer))
+SOFT_LINK(CoreVideo, CVPixelBufferLockBaseAddress, CVReturn, (CVPixelBufferRef pixelBuffer, CVOptionFlags lockFlags), (pixelBuffer, lockFlags))
+SOFT_LINK(CoreVideo, CVPixelBufferUnlockBaseAddress, CVReturn, (CVPixelBufferRef pixelBuffer, CVOptionFlags lockFlags), (pixelBuffer, lockFlags))
+
+SOFT_LINK_POINTER(CoreVideo, kCVPixelBufferPixelFormatTypeKey, NSString *)
+#define kCVPixelBufferPixelFormatTypeKey getkCVPixelBufferPixelFormatTypeKey()
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="cx"> RefPtr<AVMediaCaptureSource> AVVideoCaptureSource::create(AVCaptureDeviceType* device, const AtomicString& id, PassRefPtr<MediaConstraints> constraint)
</span><span class="lines">@@ -157,7 +170,6 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-NSLog(@"set frame rate to %f", [bestFrameRateRange minFrameRate]);
</del><span class="cx"> LOG(Media, "AVVideoCaptureSource::setFrameRateConstraint(%p) - set frame rate range to %f..%f", this, minFrameRate, maxFrameRate);
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="lines">@@ -209,26 +221,29 @@
</span><span class="cx"> ASSERT([session() canAddInput:videoIn.get()]);
</span><span class="cx"> if ([session() canAddInput:videoIn.get()])
</span><span class="cx"> [session() addInput:videoIn.get()];
</span><del>-
</del><ins>+
</ins><span class="cx"> if (constraints())
</span><span class="cx"> applyConstraints(constraints());
</span><span class="cx">
</span><span class="cx"> RetainPtr<AVCaptureVideoDataOutputType> videoOutput = adoptNS([allocAVCaptureVideoDataOutputInstance() init]);
</span><ins>+ RetainPtr<NSDictionary> settingsDictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey
+ , nil]);
+ [videoOutput setVideoSettings:settingsDictionary.get()];
</ins><span class="cx"> setVideoSampleBufferDelegate(videoOutput.get());
</span><span class="cx"> ASSERT([session() canAddOutput:videoOutput.get()]);
</span><span class="cx"> if ([session() canAddOutput:videoOutput.get()])
</span><span class="cx"> [session() addOutput:videoOutput.get()];
</span><del>-
</del><ins>+
</ins><span class="cx"> m_videoConnection = adoptNS([videoOutput.get() connectionWithMediaType:AVMediaTypeVideo]);
</span><del>-
</del><span class="cx"> m_videoPreviewLayer = adoptNS([[AVCaptureVideoPreviewLayer alloc] initWithSession:session()]);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void AVVideoCaptureSource::calculateFramerate(CMSampleBufferRef sampleBuffer)
</del><ins>+bool AVVideoCaptureSource::calculateFramerate(CMSampleBufferRef sampleBuffer)
</ins><span class="cx"> {
</span><span class="cx"> CMTime sampleTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
</span><span class="cx"> if (!CMTIME_IS_NUMERIC(sampleTime))
</span><del>- return;
</del><ins>+ return false;
</ins><span class="cx">
</span><span class="cx"> Float64 frameTime = CMTimeGetSeconds(sampleTime);
</span><span class="cx"> Float64 oneSecondAgo = frameTime - 1;
</span><span class="lines">@@ -237,27 +252,83 @@
</span><span class="cx">
</span><span class="cx"> while (m_videoFrameTimeStamps[0] < oneSecondAgo)
</span><span class="cx"> m_videoFrameTimeStamps.remove(0);
</span><del>-
</del><ins>+
+ Float64 frameRate = m_frameRate;
</ins><span class="cx"> m_frameRate = (m_frameRate + m_videoFrameTimeStamps.size()) / 2;
</span><ins>+
+ return frameRate != m_frameRate;
</ins><span class="cx"> }
</span><del>-
-void AVVideoCaptureSource::captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutputType*, CMSampleBufferRef sampleBuffer, AVCaptureConnectionType*)
</del><ins>+
+void AVVideoCaptureSource::processNewFrame(RetainPtr<CMSampleBufferRef> sampleBuffer)
</ins><span class="cx"> {
</span><del>- CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
</del><ins>+ CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer.get());
</ins><span class="cx"> if (!formatDescription)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- CFRetain(formatDescription);
- m_videoFormatDescription = adoptCF(formatDescription);
- calculateFramerate(sampleBuffer);
</del><ins>+ bool statesChanged = false;
</ins><span class="cx">
</span><ins>+ statesChanged = calculateFramerate(sampleBuffer.get());
+ m_buffer = sampleBuffer;
+ m_lastImage = nullptr;
+
</ins><span class="cx"> CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
</span><del>- m_width = dimensions.width;
- m_height = dimensions.height;
-
- setBuffer(sampleBuffer);
</del><ins>+ if (dimensions.width != m_width || dimensions.height != m_height) {
+ m_width = dimensions.width;
+ m_height = dimensions.height;
+ statesChanged = true;
+ }
+
+ if (statesChanged)
+ this->statesDidChanged();
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void AVVideoCaptureSource::captureOutputDidOutputSampleBufferFromConnection(AVCaptureOutputType*, CMSampleBufferRef sampleBuffer, AVCaptureConnectionType*)
+{
+ RetainPtr<CMSampleBufferRef> buffer = sampleBuffer;
+
+ scheduleDeferredTask([this, buffer] {
+ this->processNewFrame(buffer);
+ });
+}
+
+RetainPtr<CGImageRef> AVVideoCaptureSource::currentFrameImage()
+{
+ if (m_lastImage)
+ return m_lastImage;
+
+ if (!m_buffer)
+ return nullptr;
+
+ CVPixelBufferRef pixelBuffer = static_cast<CVPixelBufferRef>(CMSampleBufferGetImageBuffer(m_buffer.get()));
+ ASSERT(CVPixelBufferGetPixelFormatType(pixelBuffer) == kCVPixelFormatType_32BGRA);
+
+ CVPixelBufferLockBaseAddress(pixelBuffer, 0);
+ void *baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
+ size_t bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
+ size_t width = CVPixelBufferGetWidth(pixelBuffer);
+ size_t height = CVPixelBufferGetHeight(pixelBuffer);
+
+ RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateWithData(NULL, baseAddress, bytesPerRow * height, NULL));
+ m_lastImage = adoptCF(CGImageCreate(width, height, 8, 32, bytesPerRow, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst, provider.get(), NULL, true, kCGRenderingIntentDefault));
+
+ CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
+
+ return m_lastImage;
+}
+
+void AVVideoCaptureSource::paintCurrentFrameInContext(GraphicsContext& context, const FloatRect& rect)
+{
+ if (context.paintingDisabled() || !currentFrameImage())
+ return;
+
+ GraphicsContextStateSaver stateSaver(context);
+ context.translate(rect.x(), rect.y() + rect.height());
+ context.scale(FloatSize(1, -1));
+ context.setImageInterpolationQuality(InterpolationLow);
+ IntRect paintRect(IntPoint(0, 0), IntSize(rect.width(), rect.height()));
+ CGContextDrawImage(context.platformContext(), CGRectMake(0, 0, paintRect.width(), paintRect.height()), m_lastImage.get());
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(MEDIA_STREAM)
</span></span></pre>
</div>
</div>
</body>
</html>