Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: content/renderer/media/video_frame_deliverer.cc

Issue 264363005: Cast: deliver video frames on the IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/video_frame_deliverer.h" 5 #include "content/renderer/media/video_frame_deliverer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 9
10 namespace content { 10 namespace content {
11 namespace {
12 void ResetCallback(VideoCaptureDeliverFrameCB callback) {
13 callback.Reset();
14 }
15 } // namespace
11 16
12 VideoFrameDeliverer::VideoFrameDeliverer( 17 VideoFrameDeliverer::VideoFrameDeliverer(
13 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) 18 const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
14 : io_message_loop_(io_message_loop) { 19 : io_message_loop_(io_message_loop) {
15 DCHECK(io_message_loop_); 20 DCHECK(io_message_loop_);
16 } 21 }
17 22
18 VideoFrameDeliverer::~VideoFrameDeliverer() { 23 VideoFrameDeliverer::~VideoFrameDeliverer() {
19 DCHECK(callbacks_.empty()); 24 DCHECK(callbacks_.empty());
20 } 25 }
(...skipping 13 matching lines...) Expand all
34 const VideoCaptureDeliverFrameCB& callback) { 39 const VideoCaptureDeliverFrameCB& callback) {
35 DCHECK(io_message_loop_->BelongsToCurrentThread()); 40 DCHECK(io_message_loop_->BelongsToCurrentThread());
36 callbacks_.push_back(std::make_pair(id, callback)); 41 callbacks_.push_back(std::make_pair(id, callback));
37 } 42 }
38 43
39 void VideoFrameDeliverer::RemoveCallback(void* id) { 44 void VideoFrameDeliverer::RemoveCallback(void* id) {
40 DCHECK(thread_checker_.CalledOnValidThread()); 45 DCHECK(thread_checker_.CalledOnValidThread());
41 io_message_loop_->PostTask( 46 io_message_loop_->PostTask(
42 FROM_HERE, 47 FROM_HERE,
43 base::Bind(&VideoFrameDeliverer::RemoveCallbackOnIO, 48 base::Bind(&VideoFrameDeliverer::RemoveCallbackOnIO,
44 this, id)); 49 this, id, base::MessageLoopProxy::current()));
45 } 50 }
46 51
47 void VideoFrameDeliverer::RemoveCallbackOnIO(void* id) { 52 void VideoFrameDeliverer::RemoveCallbackOnIO(
53 void* id, const scoped_refptr<base::MessageLoopProxy>& message_loop) {
48 DCHECK(io_message_loop_->BelongsToCurrentThread()); 54 DCHECK(io_message_loop_->BelongsToCurrentThread());
49 std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin(); 55 std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin();
50 for (; it != callbacks_.end(); ++it) { 56 for (; it != callbacks_.end(); ++it) {
51 if (it->first == id) { 57 if (it->first == id) {
58 VideoCaptureDeliverFrameCB callback = it->second;
52 callbacks_.erase(it); 59 callbacks_.erase(it);
60 message_loop->PostTask(FROM_HERE, base::Bind(&ResetCallback, callback));
piman 2014/05/09 03:44:23 So, this is racy. If the target message loop is fr
53 return; 61 return;
54 } 62 }
55 } 63 }
56 } 64 }
57 65
58 void VideoFrameDeliverer::DeliverFrameOnIO( 66 void VideoFrameDeliverer::DeliverFrameOnIO(
59 const scoped_refptr<media::VideoFrame>& frame, 67 const scoped_refptr<media::VideoFrame>& frame,
60 const media::VideoCaptureFormat& format) { 68 const media::VideoCaptureFormat& format) {
61 DCHECK(io_message_loop_->BelongsToCurrentThread()); 69 DCHECK(io_message_loop_->BelongsToCurrentThread());
62 for (std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin(); 70 for (std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin();
63 it != callbacks_.end(); ++it) { 71 it != callbacks_.end(); ++it) {
64 it->second.Run(frame, format); 72 it->second.Run(frame, format);
65 } 73 }
66 } 74 }
67 75
68 } // namespace content 76 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_frame_deliverer.h ('k') | content/renderer/media/video_source_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698