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

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 2417383002: VideoCaptureManager: fixed double-deletion bug in StopCaptureForClient() on error (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/renderer_host/media/video_capture_manager.h" 5 #include "content/browser/renderer_host/media/video_capture_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 652 }
653 653
654 void VideoCaptureManager::StartCaptureForClient( 654 void VideoCaptureManager::StartCaptureForClient(
655 media::VideoCaptureSessionId session_id, 655 media::VideoCaptureSessionId session_id,
656 const media::VideoCaptureParams& params, 656 const media::VideoCaptureParams& params,
657 base::ProcessHandle client_render_process, 657 base::ProcessHandle client_render_process,
658 VideoCaptureControllerID client_id, 658 VideoCaptureControllerID client_id,
659 VideoCaptureControllerEventHandler* client_handler, 659 VideoCaptureControllerEventHandler* client_handler,
660 const DoneCB& done_cb) { 660 const DoneCB& done_cb) {
661 DCHECK_CURRENTLY_ON(BrowserThread::IO); 661 DCHECK_CURRENTLY_ON(BrowserThread::IO);
662 DVLOG(1) << "VideoCaptureManager::StartCaptureForClient #" << session_id 662 DVLOG(1) << __func__ << ", session_id = " << session_id << ", request: "
663 << ", request: "
664 << media::VideoCaptureFormat::ToString(params.requested_format); 663 << media::VideoCaptureFormat::ToString(params.requested_format);
665 664
666 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id, params); 665 DeviceEntry* entry = GetOrCreateDeviceEntry(session_id, params);
667 if (!entry) { 666 if (!entry) {
668 done_cb.Run(base::WeakPtr<VideoCaptureController>()); 667 done_cb.Run(base::WeakPtr<VideoCaptureController>());
669 return; 668 return;
670 } 669 }
671 670
672 DCHECK(entry->video_capture_controller()); 671 DCHECK(entry->video_capture_controller());
673 672
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 LogVideoCaptureEvent(VIDEO_CAPTURE_STOP_CAPTURE_OK); 704 LogVideoCaptureEvent(VIDEO_CAPTURE_STOP_CAPTURE_OK);
706 } else if (entry->stream_type == MEDIA_DEVICE_VIDEO_CAPTURE) { 705 } else if (entry->stream_type == MEDIA_DEVICE_VIDEO_CAPTURE) {
707 LogVideoCaptureEvent( 706 LogVideoCaptureEvent(
708 VIDEO_CAPTURE_STOP_CAPTURE_OK_NO_FRAMES_PRODUCED_BY_DEVICE); 707 VIDEO_CAPTURE_STOP_CAPTURE_OK_NO_FRAMES_PRODUCED_BY_DEVICE);
709 } else { 708 } else {
710 LogVideoCaptureEvent( 709 LogVideoCaptureEvent(
711 VIDEO_CAPTURE_STOP_CAPTURE_OK_NO_FRAMES_PRODUCED_BY_DESKTOP_OR_TAB); 710 VIDEO_CAPTURE_STOP_CAPTURE_OK_NO_FRAMES_PRODUCED_BY_DESKTOP_OR_TAB);
712 } 711 }
713 } else { 712 } else {
714 LogVideoCaptureEvent(VIDEO_CAPTURE_STOP_CAPTURE_DUE_TO_ERROR); 713 LogVideoCaptureEvent(VIDEO_CAPTURE_STOP_CAPTURE_DUE_TO_ERROR);
715 SessionMap::iterator it; 714 for (auto it : sessions_) {
716 for (it = sessions_.begin(); it != sessions_.end(); ++it) { 715 if (it.second.type == entry->stream_type && it.second.id == entry->id) {
717 if (it->second.type == entry->stream_type && 716 listener_->Aborted(it.second.type, it.first);
718 it->second.id == entry->id) { 717 // Aborted() call might synchronously destroy |entry|, recheck.
xianglu 2016/10/14 23:28:22 If the entry is always going to be deleted after A
mcasas 2016/10/14 23:44:10 The |entry| might still be alive if there's more t
719 listener_->Aborted(it->second.type, it->first); 718 entry = GetDeviceEntryByController(controller);
719 if (!entry)
720 return;
720 break; 721 break;
721 } 722 }
722 } 723 }
723 } 724 }
724 725
725 // Detach client from controller. 726 // Detach client from controller.
726 media::VideoCaptureSessionId session_id = 727 const media::VideoCaptureSessionId session_id =
727 controller->RemoveClient(client_id, client_handler); 728 controller->RemoveClient(client_id, client_handler);
728 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " 729 DVLOG(1) << __func__ << ", session_id = " << session_id;
729 << session_id;
730 730
731 // If controller has no more clients, delete controller and device. 731 // If controller has no more clients, delete controller and device.
732 DestroyDeviceEntryIfNoClients(entry); 732 DestroyDeviceEntryIfNoClients(entry);
733 } 733 }
734 734
735 void VideoCaptureManager::PauseCaptureForClient( 735 void VideoCaptureManager::PauseCaptureForClient(
736 VideoCaptureController* controller, 736 VideoCaptureController* controller,
737 VideoCaptureControllerID client_id, 737 VideoCaptureControllerID client_id,
738 VideoCaptureControllerEventHandler* client_handler) { 738 VideoCaptureControllerEventHandler* client_handler) {
739 DCHECK_CURRENTLY_ON(BrowserThread::IO); 739 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 if (!device_in_queue) { 1286 if (!device_in_queue) {
1287 // Session ID is only valid for Screen capture. So we can fake it to 1287 // Session ID is only valid for Screen capture. So we can fake it to
1288 // resume video capture devices here. 1288 // resume video capture devices here.
1289 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); 1289 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters);
1290 } 1290 }
1291 } 1291 }
1292 } 1292 }
1293 #endif // defined(OS_ANDROID) 1293 #endif // defined(OS_ANDROID)
1294 1294
1295 } // namespace content 1295 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698