#include "base/stl_util.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/renderer_host/media/video_capture_manager.h"
+#include "content/common/gpu/client/gl_helper.h"
#include "content/public/browser/browser_thread.h"
#include "gpu/command_buffer/common/mailbox_holder.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "media/base/yuv_convert.h"
-
-#if !defined(AVOID_LIBYUV_FOR_ANDROID_WEBVIEW)
#include "third_party/libyuv/include/libyuv.h"
+
+#if defined(OS_ANDROID)
+#include "content/browser/renderer_host/image_transport_factory_android.h"
+#else
+#include "content/browser/compositor/image_transport_factory.h"
#endif
using media::VideoCaptureFormat;
name, \
(height) ? ((width) * 100) / (height) : kInfiniteRatio);
-// The number of buffers that VideoCaptureBufferPool should allocate.
-const int kNoOfBuffers = 3;
-
class PoolBuffer : public media::VideoCaptureDevice::Client::Buffer {
public:
PoolBuffer(const scoped_refptr<VideoCaptureBufferPool>& pool,
const scoped_refptr<VideoCaptureBufferPool> pool_;
};
+class SyncPointClientImpl : public media::VideoFrame::SyncPointClient {
+ public:
+ explicit SyncPointClientImpl(GLHelper* gl_helper) : gl_helper_(gl_helper) {}
+ virtual ~SyncPointClientImpl() {}
+ virtual uint32 InsertSyncPoint() OVERRIDE {
+ return gl_helper_->InsertSyncPoint();
+ }
+ virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE {
+ gl_helper_->WaitSyncPoint(sync_point);
+ }
+
+ private:
+ GLHelper* gl_helper_;
+};
+
+void ReturnVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame,
+ uint32 sync_point) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+#if defined(OS_ANDROID)
+ GLHelper* gl_helper =
+ ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
+#else
+ GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
+#endif
+ DCHECK(gl_helper);
+ // UpdateReleaseSyncPoint() creates a new sync_point using |gl_helper|, so
+ // wait the given |sync_point| using |gl_helper|.
+ gl_helper->WaitSyncPoint(sync_point);
+ SyncPointClientImpl client(gl_helper);
+ video_frame->UpdateReleaseSyncPoint(&client);
+}
+
} // anonymous namespace
struct VideoCaptureController::ControllerClient {
const scoped_refptr<media::VideoFrame>& frame,
base::TimeTicks timestamp) OVERRIDE;
virtual void OnError(const std::string& reason) OVERRIDE;
+ virtual void OnLog(const std::string& message) OVERRIDE;
private:
scoped_refptr<Buffer> DoReserveOutputBuffer(media::VideoFrame::Format format,
bool first_frame_;
};
-VideoCaptureController::VideoCaptureController()
- : buffer_pool_(new VideoCaptureBufferPool(kNoOfBuffers)),
+VideoCaptureController::VideoCaptureController(int max_buffers)
+ : buffer_pool_(new VideoCaptureBufferPool(max_buffers)),
state_(VIDEO_CAPTURE_STATE_STARTED),
weak_ptr_factory_(this) {
}
base::ProcessHandle render_process,
media::VideoCaptureSessionId session_id,
const media::VideoCaptureParams& params) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
DVLOG(1) << "VideoCaptureController::AddClient, id " << id.device_id
<< ", " << params.requested_format.frame_size.ToString()
<< ", " << params.requested_format.frame_rate
int VideoCaptureController::RemoveClient(
const VideoCaptureControllerID& id,
VideoCaptureControllerEventHandler* event_handler) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id.device_id;
ControllerClient* client = FindClient(id, event_handler, controller_clients_);
}
void VideoCaptureController::StopSession(int session_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
DVLOG(1) << "VideoCaptureController::StopSession, id " << session_id;
ControllerClient* client = FindClient(session_id, controller_clients_);
VideoCaptureControllerEventHandler* event_handler,
int buffer_id,
uint32 sync_point) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
ControllerClient* client = FindClient(id, event_handler, controller_clients_);
}
scoped_refptr<media::VideoFrame> frame = iter->second;
client->active_buffers.erase(iter);
-
- if (frame->format() == media::VideoFrame::NATIVE_TEXTURE)
- frame->mailbox_holder()->sync_point = sync_point;
-
buffer_pool_->RelinquishConsumerHold(buffer_id, 1);
+
+ if (sync_point)
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&ReturnVideoFrame, frame, sync_point));
}
const media::VideoCaptureFormat&
VideoCaptureController::GetVideoCaptureFormat() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
return video_capture_format_;
}
if (!buffer)
return;
uint8* yplane = NULL;
-#if !defined(AVOID_LIBYUV_FOR_ANDROID_WEBVIEW)
bool flip = false;
yplane = reinterpret_cast<uint8*>(buffer->data());
uint8* uplane =
new_unrotated_height,
rotation_mode,
origin_colorspace);
-#else
- // Libyuv is not linked in for Android WebView builds, but video capture is
- // not used in those builds either. Whenever libyuv is added in that build,
- // address all these #ifdef parts, see http://crbug.com/299611 .
- NOTREACHED();
-#endif // if !defined(AVOID_LIBYUV_FOR_ANDROID_WEBVIEW)
scoped_refptr<media::VideoFrame> frame =
media::VideoFrame::WrapExternalPackedMemory(
media::VideoFrame::I420,
base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_));
}
+void VideoCaptureController::VideoCaptureDeviceClient::OnLog(
+ const std::string& message) {
+ MediaStreamManager::SendMessageToNativeLog("Video capture: " + message);
+}
+
scoped_refptr<media::VideoCaptureDevice::Client::Buffer>
VideoCaptureController::VideoCaptureDeviceClient::DoReserveOutputBuffer(
media::VideoFrame::Format format,
const media::VideoCaptureFormat& buffer_format,
const scoped_refptr<media::VideoFrame>& frame,
base::TimeTicks timestamp) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_NE(buffer->id(), VideoCaptureBufferPool::kInvalidId);
int count = 0;
}
void VideoCaptureController::DoErrorOnIOThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
state_ = VIDEO_CAPTURE_STATE_ERROR;
for (ControllerClients::iterator client_it = controller_clients_.begin();
void VideoCaptureController::DoBufferDestroyedOnIOThread(
int buffer_id_to_drop) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
for (ControllerClients::iterator client_it = controller_clients_.begin();
client_it != controller_clients_.end(); ++client_it) {
}
int VideoCaptureController::GetClientCount() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
return controller_clients_.size();
}