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

Side by Side Diff: media/gpu/v4l2_video_decode_accelerator.cc

Issue 2076423004: Remove calls to MessageLoop::current() in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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 "media/gpu/v4l2_video_decode_accelerator.h" 5 #include "media/gpu/v4l2_video_decode_accelerator.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <linux/videodev2.h> 10 #include <linux/videodev2.h>
11 #include <poll.h> 11 #include <poll.h>
12 #include <string.h> 12 #include <string.h>
13 #include <sys/eventfd.h> 13 #include <sys/eventfd.h>
14 #include <sys/ioctl.h> 14 #include <sys/ioctl.h>
15 #include <sys/mman.h> 15 #include <sys/mman.h>
16 16
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/numerics/safe_conversions.h" 20 #include "base/numerics/safe_conversions.h"
21 #include "base/single_thread_task_runner.h"
21 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/trace_event/trace_event.h" 23 #include "base/trace_event/trace_event.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 #include "media/base/bind_to_current_loop.h" 25 #include "media/base/bind_to_current_loop.h"
25 #include "media/base/media_switches.h" 26 #include "media/base/media_switches.h"
26 #include "media/filters/h264_parser.h" 27 #include "media/filters/h264_parser.h"
27 #include "media/gpu/shared_memory_region.h" 28 #include "media/gpu/shared_memory_region.h"
28 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
29 #include "ui/gl/gl_context.h" 30 #include "ui/gl/gl_context.h"
30 #include "ui/gl/scoped_binders.h" 31 #include "ui/gl/scoped_binders.h"
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (!device) 526 if (!device)
526 return SupportedProfiles(); 527 return SupportedProfiles();
527 528
528 return device->GetSupportedDecodeProfiles(arraysize(supported_input_fourccs_), 529 return device->GetSupportedDecodeProfiles(arraysize(supported_input_fourccs_),
529 supported_input_fourccs_); 530 supported_input_fourccs_);
530 } 531 }
531 532
532 void V4L2VideoDecodeAccelerator::DecodeTask( 533 void V4L2VideoDecodeAccelerator::DecodeTask(
533 const BitstreamBuffer& bitstream_buffer) { 534 const BitstreamBuffer& bitstream_buffer) {
534 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); 535 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id();
535 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 536 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
536 DCHECK_NE(decoder_state_, kUninitialized); 537 DCHECK_NE(decoder_state_, kUninitialized);
537 TRACE_EVENT1("Video Decoder", "V4L2VDA::DecodeTask", "input_id", 538 TRACE_EVENT1("Video Decoder", "V4L2VDA::DecodeTask", "input_id",
538 bitstream_buffer.id()); 539 bitstream_buffer.id());
539 540
540 std::unique_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( 541 std::unique_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef(
541 decode_client_, decode_task_runner_, 542 decode_client_, decode_task_runner_,
542 std::unique_ptr<SharedMemoryRegion>( 543 std::unique_ptr<SharedMemoryRegion>(
543 new SharedMemoryRegion(bitstream_buffer, true)), 544 new SharedMemoryRegion(bitstream_buffer, true)),
544 bitstream_buffer.id())); 545 bitstream_buffer.id()));
545 546
(...skipping 22 matching lines...) Expand all
568 } 569 }
569 570
570 decoder_input_queue_.push( 571 decoder_input_queue_.push(
571 linked_ptr<BitstreamBufferRef>(bitstream_record.release())); 572 linked_ptr<BitstreamBufferRef>(bitstream_record.release()));
572 decoder_decode_buffer_tasks_scheduled_++; 573 decoder_decode_buffer_tasks_scheduled_++;
573 DecodeBufferTask(); 574 DecodeBufferTask();
574 } 575 }
575 576
576 void V4L2VideoDecodeAccelerator::DecodeBufferTask() { 577 void V4L2VideoDecodeAccelerator::DecodeBufferTask() {
577 DVLOG(3) << "DecodeBufferTask()"; 578 DVLOG(3) << "DecodeBufferTask()";
578 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 579 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
579 DCHECK_NE(decoder_state_, kUninitialized); 580 DCHECK_NE(decoder_state_, kUninitialized);
580 TRACE_EVENT0("Video Decoder", "V4L2VDA::DecodeBufferTask"); 581 TRACE_EVENT0("Video Decoder", "V4L2VDA::DecodeBufferTask");
581 582
582 decoder_decode_buffer_tasks_scheduled_--; 583 decoder_decode_buffer_tasks_scheduled_--;
583 584
584 if (decoder_state_ == kResetting) { 585 if (decoder_state_ == kResetting) {
585 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state"; 586 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state";
586 return; 587 return;
587 } else if (decoder_state_ == kError) { 588 } else if (decoder_state_ == kError) {
588 DVLOG(2) << "DecodeBufferTask(): early out: kError state"; 589 DVLOG(2) << "DecodeBufferTask(): early out: kError state";
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 DCHECK_LE(video_profile_, VP9PROFILE_MAX); 771 DCHECK_LE(video_profile_, VP9PROFILE_MAX);
771 // For VP8/9, we can just dump the entire buffer. No fragmentation needed, 772 // For VP8/9, we can just dump the entire buffer. No fragmentation needed,
772 // and we never return a partial frame. 773 // and we never return a partial frame.
773 *endpos = size; 774 *endpos = size;
774 decoder_partial_frame_pending_ = false; 775 decoder_partial_frame_pending_ = false;
775 return true; 776 return true;
776 } 777 }
777 } 778 }
778 779
779 void V4L2VideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { 780 void V4L2VideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() {
780 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 781 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
781 782
782 // If we're behind on tasks, schedule another one. 783 // If we're behind on tasks, schedule another one.
783 int buffers_to_decode = decoder_input_queue_.size(); 784 int buffers_to_decode = decoder_input_queue_.size();
784 if (decoder_current_bitstream_buffer_ != NULL) 785 if (decoder_current_bitstream_buffer_ != NULL)
785 buffers_to_decode++; 786 buffers_to_decode++;
786 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { 787 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) {
787 decoder_decode_buffer_tasks_scheduled_++; 788 decoder_decode_buffer_tasks_scheduled_++;
788 decoder_thread_.message_loop()->PostTask( 789 decoder_thread_.message_loop()->PostTask(
789 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::DecodeBufferTask, 790 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::DecodeBufferTask,
790 base::Unretained(this))); 791 base::Unretained(this)));
791 } 792 }
792 } 793 }
793 794
794 bool V4L2VideoDecodeAccelerator::DecodeBufferInitial(const void* data, 795 bool V4L2VideoDecodeAccelerator::DecodeBufferInitial(const void* data,
795 size_t size, 796 size_t size,
796 size_t* endpos) { 797 size_t* endpos) {
797 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; 798 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size;
798 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 799 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
799 DCHECK_NE(decoder_state_, kUninitialized); 800 DCHECK_NE(decoder_state_, kUninitialized);
800 DCHECK_NE(decoder_state_, kDecoding); 801 DCHECK_NE(decoder_state_, kDecoding);
801 // Initial decode. We haven't been able to get output stream format info yet. 802 // Initial decode. We haven't been able to get output stream format info yet.
802 // Get it, and start decoding. 803 // Get it, and start decoding.
803 804
804 // Copy in and send to HW. 805 // Copy in and send to HW.
805 if (!AppendToInputFrame(data, size)) 806 if (!AppendToInputFrame(data, size))
806 return false; 807 return false;
807 808
808 // If we only have a partial frame, don't flush and process yet. 809 // If we only have a partial frame, don't flush and process yet.
(...skipping 29 matching lines...) Expand all
838 } 839 }
839 840
840 decoder_state_ = kDecoding; 841 decoder_state_ = kDecoding;
841 ScheduleDecodeBufferTaskIfNeeded(); 842 ScheduleDecodeBufferTaskIfNeeded();
842 return true; 843 return true;
843 } 844 }
844 845
845 bool V4L2VideoDecodeAccelerator::DecodeBufferContinue(const void* data, 846 bool V4L2VideoDecodeAccelerator::DecodeBufferContinue(const void* data,
846 size_t size) { 847 size_t size) {
847 DVLOG(3) << "DecodeBufferContinue(): data=" << data << ", size=" << size; 848 DVLOG(3) << "DecodeBufferContinue(): data=" << data << ", size=" << size;
848 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 849 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
849 DCHECK_EQ(decoder_state_, kDecoding); 850 DCHECK_EQ(decoder_state_, kDecoding);
850 851
851 // Both of these calls will set kError state if they fail. 852 // Both of these calls will set kError state if they fail.
852 // Only flush the frame if it's complete. 853 // Only flush the frame if it's complete.
853 return (AppendToInputFrame(data, size) && 854 return (AppendToInputFrame(data, size) &&
854 (decoder_partial_frame_pending_ || FlushInputFrame())); 855 (decoder_partial_frame_pending_ || FlushInputFrame()));
855 } 856 }
856 857
857 bool V4L2VideoDecodeAccelerator::AppendToInputFrame(const void* data, 858 bool V4L2VideoDecodeAccelerator::AppendToInputFrame(const void* data,
858 size_t size) { 859 size_t size) {
859 DVLOG(3) << "AppendToInputFrame()"; 860 DVLOG(3) << "AppendToInputFrame()";
860 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 861 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
861 DCHECK_NE(decoder_state_, kUninitialized); 862 DCHECK_NE(decoder_state_, kUninitialized);
862 DCHECK_NE(decoder_state_, kResetting); 863 DCHECK_NE(decoder_state_, kResetting);
863 DCHECK_NE(decoder_state_, kError); 864 DCHECK_NE(decoder_state_, kError);
864 // This routine can handle data == NULL and size == 0, which occurs when 865 // This routine can handle data == NULL and size == 0, which occurs when
865 // we queue an empty buffer for the purposes of flushing the pipe. 866 // we queue an empty buffer for the purposes of flushing the pipe.
866 867
867 // Flush if we're too big 868 // Flush if we're too big
868 if (decoder_current_input_buffer_ != -1) { 869 if (decoder_current_input_buffer_ != -1) {
869 InputRecord& input_record = 870 InputRecord& input_record =
870 input_buffer_map_[decoder_current_input_buffer_]; 871 input_buffer_map_[decoder_current_input_buffer_];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 memcpy(reinterpret_cast<uint8_t*>(input_record.address) + 915 memcpy(reinterpret_cast<uint8_t*>(input_record.address) +
915 input_record.bytes_used, 916 input_record.bytes_used,
916 data, size); 917 data, size);
917 input_record.bytes_used += size; 918 input_record.bytes_used += size;
918 919
919 return true; 920 return true;
920 } 921 }
921 922
922 bool V4L2VideoDecodeAccelerator::FlushInputFrame() { 923 bool V4L2VideoDecodeAccelerator::FlushInputFrame() {
923 DVLOG(3) << "FlushInputFrame()"; 924 DVLOG(3) << "FlushInputFrame()";
924 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 925 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
925 DCHECK_NE(decoder_state_, kUninitialized); 926 DCHECK_NE(decoder_state_, kUninitialized);
926 DCHECK_NE(decoder_state_, kResetting); 927 DCHECK_NE(decoder_state_, kResetting);
927 DCHECK_NE(decoder_state_, kError); 928 DCHECK_NE(decoder_state_, kError);
928 929
929 if (decoder_current_input_buffer_ == -1) 930 if (decoder_current_input_buffer_ == -1)
930 return true; 931 return true;
931 932
932 InputRecord& input_record = input_buffer_map_[decoder_current_input_buffer_]; 933 InputRecord& input_record = input_buffer_map_[decoder_current_input_buffer_];
933 DCHECK_NE(input_record.input_id, -1); 934 DCHECK_NE(input_record.input_id, -1);
934 DCHECK(input_record.input_id != kFlushBufferId || 935 DCHECK(input_record.input_id != kFlushBufferId ||
(...skipping 16 matching lines...) Expand all
951 DVLOG(3) << "FlushInputFrame(): submitting input_id=" 952 DVLOG(3) << "FlushInputFrame(): submitting input_id="
952 << input_record.input_id; 953 << input_record.input_id;
953 // Enqueue once since there's new available input for it. 954 // Enqueue once since there's new available input for it.
954 Enqueue(); 955 Enqueue();
955 956
956 return (decoder_state_ != kError); 957 return (decoder_state_ != kError);
957 } 958 }
958 959
959 void V4L2VideoDecodeAccelerator::ServiceDeviceTask(bool event_pending) { 960 void V4L2VideoDecodeAccelerator::ServiceDeviceTask(bool event_pending) {
960 DVLOG(3) << "ServiceDeviceTask()"; 961 DVLOG(3) << "ServiceDeviceTask()";
961 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 962 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
962 DCHECK_NE(decoder_state_, kUninitialized); 963 DCHECK_NE(decoder_state_, kUninitialized);
963 TRACE_EVENT0("Video Decoder", "V4L2VDA::ServiceDeviceTask"); 964 TRACE_EVENT0("Video Decoder", "V4L2VDA::ServiceDeviceTask");
964 965
965 if (decoder_state_ == kResetting) { 966 if (decoder_state_ == kResetting) {
966 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; 967 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state";
967 return; 968 return;
968 } else if (decoder_state_ == kError) { 969 } else if (decoder_state_ == kError) {
969 DVLOG(2) << "ServiceDeviceTask(): early out: kError state"; 970 DVLOG(2) << "ServiceDeviceTask(): early out: kError state";
970 return; 971 return;
971 } else if (decoder_state_ == kChangingResolution) { 972 } else if (decoder_state_ == kChangingResolution) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 << image_processor_bitstream_buffer_ids_.size() << "] => CLIENT[" 1016 << image_processor_bitstream_buffer_ids_.size() << "] => CLIENT["
1016 << decoder_frames_at_client_ << "]"; 1017 << decoder_frames_at_client_ << "]";
1017 1018
1018 ScheduleDecodeBufferTaskIfNeeded(); 1019 ScheduleDecodeBufferTaskIfNeeded();
1019 if (resolution_change_pending) 1020 if (resolution_change_pending)
1020 StartResolutionChange(); 1021 StartResolutionChange();
1021 } 1022 }
1022 1023
1023 void V4L2VideoDecodeAccelerator::Enqueue() { 1024 void V4L2VideoDecodeAccelerator::Enqueue() {
1024 DVLOG(3) << "Enqueue()"; 1025 DVLOG(3) << "Enqueue()";
1025 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1026 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1026 DCHECK_NE(decoder_state_, kUninitialized); 1027 DCHECK_NE(decoder_state_, kUninitialized);
1027 TRACE_EVENT0("Video Decoder", "V4L2VDA::Enqueue"); 1028 TRACE_EVENT0("Video Decoder", "V4L2VDA::Enqueue");
1028 1029
1029 // Drain the pipe of completed decode buffers. 1030 // Drain the pipe of completed decode buffers.
1030 const int old_inputs_queued = input_buffer_queued_count_; 1031 const int old_inputs_queued = input_buffer_queued_count_;
1031 while (!input_ready_queue_.empty()) { 1032 while (!input_ready_queue_.empty()) {
1032 if (!EnqueueInputRecord()) 1033 if (!EnqueueInputRecord())
1033 return; 1034 return;
1034 } 1035 }
1035 if (old_inputs_queued == 0 && input_buffer_queued_count_ != 0) { 1036 if (old_inputs_queued == 0 && input_buffer_queued_count_ != 0) {
(...skipping 29 matching lines...) Expand all
1065 // Start VIDIOC_STREAMON if we haven't yet. 1066 // Start VIDIOC_STREAMON if we haven't yet.
1066 if (!output_streamon_) { 1067 if (!output_streamon_) {
1067 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1068 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1068 IOCTL_OR_ERROR_RETURN(VIDIOC_STREAMON, &type); 1069 IOCTL_OR_ERROR_RETURN(VIDIOC_STREAMON, &type);
1069 output_streamon_ = true; 1070 output_streamon_ = true;
1070 } 1071 }
1071 } 1072 }
1072 } 1073 }
1073 1074
1074 bool V4L2VideoDecodeAccelerator::DequeueResolutionChangeEvent() { 1075 bool V4L2VideoDecodeAccelerator::DequeueResolutionChangeEvent() {
1075 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1076 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1076 DCHECK_NE(decoder_state_, kUninitialized); 1077 DCHECK_NE(decoder_state_, kUninitialized);
1077 DVLOG(3) << "DequeueResolutionChangeEvent()"; 1078 DVLOG(3) << "DequeueResolutionChangeEvent()";
1078 1079
1079 struct v4l2_event ev; 1080 struct v4l2_event ev;
1080 memset(&ev, 0, sizeof(ev)); 1081 memset(&ev, 0, sizeof(ev));
1081 1082
1082 while (device_->Ioctl(VIDIOC_DQEVENT, &ev) == 0) { 1083 while (device_->Ioctl(VIDIOC_DQEVENT, &ev) == 0) {
1083 if (ev.type == V4L2_EVENT_SOURCE_CHANGE) { 1084 if (ev.type == V4L2_EVENT_SOURCE_CHANGE) {
1084 if (ev.u.src_change.changes & V4L2_EVENT_SRC_CH_RESOLUTION) { 1085 if (ev.u.src_change.changes & V4L2_EVENT_SRC_CH_RESOLUTION) {
1085 DVLOG(3) 1086 DVLOG(3)
1086 << "DequeueResolutionChangeEvent(): got resolution change event."; 1087 << "DequeueResolutionChangeEvent(): got resolution change event.";
1087 return true; 1088 return true;
1088 } 1089 }
1089 } else { 1090 } else {
1090 LOG(ERROR) << "DequeueResolutionChangeEvent(): got an event (" << ev.type 1091 LOG(ERROR) << "DequeueResolutionChangeEvent(): got an event (" << ev.type
1091 << ") we haven't subscribed to."; 1092 << ") we haven't subscribed to.";
1092 } 1093 }
1093 } 1094 }
1094 return false; 1095 return false;
1095 } 1096 }
1096 1097
1097 void V4L2VideoDecodeAccelerator::Dequeue() { 1098 void V4L2VideoDecodeAccelerator::Dequeue() {
1098 DVLOG(3) << "Dequeue()"; 1099 DVLOG(3) << "Dequeue()";
1099 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1100 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1100 DCHECK_NE(decoder_state_, kUninitialized); 1101 DCHECK_NE(decoder_state_, kUninitialized);
1101 TRACE_EVENT0("Video Decoder", "V4L2VDA::Dequeue"); 1102 TRACE_EVENT0("Video Decoder", "V4L2VDA::Dequeue");
1102 1103
1103 // Dequeue completed input (VIDEO_OUTPUT) buffers, and recycle to the free 1104 // Dequeue completed input (VIDEO_OUTPUT) buffers, and recycle to the free
1104 // list. 1105 // list.
1105 while (input_buffer_queued_count_ > 0) { 1106 while (input_buffer_queued_count_ > 0) {
1106 DCHECK(input_streamon_); 1107 DCHECK(input_streamon_);
1107 struct v4l2_buffer dqbuf; 1108 struct v4l2_buffer dqbuf;
1108 struct v4l2_plane planes[1]; 1109 struct v4l2_plane planes[1];
1109 memset(&dqbuf, 0, sizeof(dqbuf)); 1110 memset(&dqbuf, 0, sizeof(dqbuf));
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 output_record.state = kAtDevice; 1275 output_record.state = kAtDevice;
1275 output_buffer_queued_count_++; 1276 output_buffer_queued_count_++;
1276 return true; 1277 return true;
1277 } 1278 }
1278 1279
1279 void V4L2VideoDecodeAccelerator::ReusePictureBufferTask( 1280 void V4L2VideoDecodeAccelerator::ReusePictureBufferTask(
1280 int32_t picture_buffer_id, 1281 int32_t picture_buffer_id,
1281 std::unique_ptr<EGLSyncKHRRef> egl_sync_ref) { 1282 std::unique_ptr<EGLSyncKHRRef> egl_sync_ref) {
1282 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id=" 1283 DVLOG(3) << "ReusePictureBufferTask(): picture_buffer_id="
1283 << picture_buffer_id; 1284 << picture_buffer_id;
1284 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1285 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1285 TRACE_EVENT0("Video Decoder", "V4L2VDA::ReusePictureBufferTask"); 1286 TRACE_EVENT0("Video Decoder", "V4L2VDA::ReusePictureBufferTask");
1286 1287
1287 // We run ReusePictureBufferTask even if we're in kResetting. 1288 // We run ReusePictureBufferTask even if we're in kResetting.
1288 if (decoder_state_ == kError) { 1289 if (decoder_state_ == kError) {
1289 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; 1290 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state";
1290 return; 1291 return;
1291 } 1292 }
1292 1293
1293 if (decoder_state_ == kChangingResolution) { 1294 if (decoder_state_ == kChangingResolution) {
1294 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution"; 1295 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution";
(...skipping 29 matching lines...) Expand all
1324 free_output_buffers_.push(index); 1325 free_output_buffers_.push(index);
1325 decoder_frames_at_client_--; 1326 decoder_frames_at_client_--;
1326 // Take ownership of the EGLSync. 1327 // Take ownership of the EGLSync.
1327 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR; 1328 egl_sync_ref->egl_sync = EGL_NO_SYNC_KHR;
1328 // We got a buffer back, so enqueue it back. 1329 // We got a buffer back, so enqueue it back.
1329 Enqueue(); 1330 Enqueue();
1330 } 1331 }
1331 1332
1332 void V4L2VideoDecodeAccelerator::FlushTask() { 1333 void V4L2VideoDecodeAccelerator::FlushTask() {
1333 DVLOG(3) << "FlushTask()"; 1334 DVLOG(3) << "FlushTask()";
1334 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1335 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1335 TRACE_EVENT0("Video Decoder", "V4L2VDA::FlushTask"); 1336 TRACE_EVENT0("Video Decoder", "V4L2VDA::FlushTask");
1336 1337
1337 // Flush outstanding buffers. 1338 // Flush outstanding buffers.
1338 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) { 1339 if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) {
1339 // There's nothing in the pipe, so return done immediately. 1340 // There's nothing in the pipe, so return done immediately.
1340 DVLOG(3) << "FlushTask(): returning flush"; 1341 DVLOG(3) << "FlushTask(): returning flush";
1341 child_task_runner_->PostTask(FROM_HERE, 1342 child_task_runner_->PostTask(FROM_HERE,
1342 base::Bind(&Client::NotifyFlushDone, client_)); 1343 base::Bind(&Client::NotifyFlushDone, client_));
1343 return; 1344 return;
1344 } else if (decoder_state_ == kError) { 1345 } else if (decoder_state_ == kError) {
1345 DVLOG(2) << "FlushTask(): early out: kError state"; 1346 DVLOG(2) << "FlushTask(): early out: kError state";
1346 return; 1347 return;
1347 } 1348 }
1348 1349
1349 // We don't support stacked flushing. 1350 // We don't support stacked flushing.
1350 DCHECK(!decoder_flushing_); 1351 DCHECK(!decoder_flushing_);
1351 1352
1352 // Queue up an empty buffer -- this triggers the flush. 1353 // Queue up an empty buffer -- this triggers the flush.
1353 decoder_input_queue_.push( 1354 decoder_input_queue_.push(
1354 linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef( 1355 linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef(
1355 decode_client_, decode_task_runner_, nullptr, kFlushBufferId))); 1356 decode_client_, decode_task_runner_, nullptr, kFlushBufferId)));
1356 decoder_flushing_ = true; 1357 decoder_flushing_ = true;
1357 SendPictureReady(); // Send all pending PictureReady. 1358 SendPictureReady(); // Send all pending PictureReady.
1358 1359
1359 ScheduleDecodeBufferTaskIfNeeded(); 1360 ScheduleDecodeBufferTaskIfNeeded();
1360 } 1361 }
1361 1362
1362 void V4L2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() { 1363 void V4L2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() {
1363 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1364 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1364 if (!decoder_flushing_) 1365 if (!decoder_flushing_)
1365 return; 1366 return;
1366 1367
1367 // Pipeline is empty when: 1368 // Pipeline is empty when:
1368 // * Decoder input queue is empty of non-delayed buffers. 1369 // * Decoder input queue is empty of non-delayed buffers.
1369 // * There is no currently filling input buffer. 1370 // * There is no currently filling input buffer.
1370 // * Input holding queue is empty. 1371 // * Input holding queue is empty.
1371 // * All input (VIDEO_OUTPUT) buffers are returned. 1372 // * All input (VIDEO_OUTPUT) buffers are returned.
1372 // * All image processor buffers are returned. 1373 // * All image processor buffers are returned.
1373 if (!decoder_input_queue_.empty()) { 1374 if (!decoder_input_queue_.empty()) {
(...skipping 28 matching lines...) Expand all
1402 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; 1403 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush";
1403 child_task_runner_->PostTask(FROM_HERE, 1404 child_task_runner_->PostTask(FROM_HERE,
1404 base::Bind(&Client::NotifyFlushDone, client_)); 1405 base::Bind(&Client::NotifyFlushDone, client_));
1405 1406
1406 // While we were flushing, we early-outed DecodeBufferTask()s. 1407 // While we were flushing, we early-outed DecodeBufferTask()s.
1407 ScheduleDecodeBufferTaskIfNeeded(); 1408 ScheduleDecodeBufferTaskIfNeeded();
1408 } 1409 }
1409 1410
1410 void V4L2VideoDecodeAccelerator::ResetTask() { 1411 void V4L2VideoDecodeAccelerator::ResetTask() {
1411 DVLOG(3) << "ResetTask()"; 1412 DVLOG(3) << "ResetTask()";
1412 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1413 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1413 TRACE_EVENT0("Video Decoder", "V4L2VDA::ResetTask"); 1414 TRACE_EVENT0("Video Decoder", "V4L2VDA::ResetTask");
1414 1415
1415 if (decoder_state_ == kError) { 1416 if (decoder_state_ == kError) {
1416 DVLOG(2) << "ResetTask(): early out: kError state"; 1417 DVLOG(2) << "ResetTask(): early out: kError state";
1417 return; 1418 return;
1418 } 1419 }
1419 1420
1420 // If we are in the middle of switching resolutions, postpone reset until 1421 // If we are in the middle of switching resolutions, postpone reset until
1421 // it's done. We don't have to worry about timing of this wrt to decoding, 1422 // it's done. We don't have to worry about timing of this wrt to decoding,
1422 // because output pipe is already stopped if we are changing resolution. 1423 // because output pipe is already stopped if we are changing resolution.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 // jobs will early-out in the kResetting state. 1463 // jobs will early-out in the kResetting state.
1463 decoder_state_ = kResetting; 1464 decoder_state_ = kResetting;
1464 SendPictureReady(); // Send all pending PictureReady. 1465 SendPictureReady(); // Send all pending PictureReady.
1465 decoder_thread_.message_loop()->PostTask( 1466 decoder_thread_.message_loop()->PostTask(
1466 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::ResetDoneTask, 1467 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::ResetDoneTask,
1467 base::Unretained(this))); 1468 base::Unretained(this)));
1468 } 1469 }
1469 1470
1470 void V4L2VideoDecodeAccelerator::ResetDoneTask() { 1471 void V4L2VideoDecodeAccelerator::ResetDoneTask() {
1471 DVLOG(3) << "ResetDoneTask()"; 1472 DVLOG(3) << "ResetDoneTask()";
1472 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1473 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1473 TRACE_EVENT0("Video Decoder", "V4L2VDA::ResetDoneTask"); 1474 TRACE_EVENT0("Video Decoder", "V4L2VDA::ResetDoneTask");
1474 1475
1475 if (decoder_state_ == kError) { 1476 if (decoder_state_ == kError) {
1476 DVLOG(2) << "ResetDoneTask(): early out: kError state"; 1477 DVLOG(2) << "ResetDoneTask(): early out: kError state";
1477 return; 1478 return;
1478 } 1479 }
1479 1480
1480 if (!StartDevicePoll()) 1481 if (!StartDevicePoll())
1481 return; 1482 return;
1482 1483
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 decoder_input_queue_.pop(); 1523 decoder_input_queue_.pop();
1523 decoder_flushing_ = false; 1524 decoder_flushing_ = false;
1524 1525
1525 // Set our state to kError. Just in case. 1526 // Set our state to kError. Just in case.
1526 decoder_state_ = kError; 1527 decoder_state_ = kError;
1527 } 1528 }
1528 1529
1529 bool V4L2VideoDecodeAccelerator::StartDevicePoll() { 1530 bool V4L2VideoDecodeAccelerator::StartDevicePoll() {
1530 DVLOG(3) << "StartDevicePoll()"; 1531 DVLOG(3) << "StartDevicePoll()";
1531 DCHECK(!device_poll_thread_.IsRunning()); 1532 DCHECK(!device_poll_thread_.IsRunning());
1532 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1533 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1533 1534
1534 // Start up the device poll thread and schedule its first DevicePollTask(). 1535 // Start up the device poll thread and schedule its first DevicePollTask().
1535 if (!device_poll_thread_.Start()) { 1536 if (!device_poll_thread_.Start()) {
1536 LOG(ERROR) << "StartDevicePoll(): Device thread failed to start"; 1537 LOG(ERROR) << "StartDevicePoll(): Device thread failed to start";
1537 NOTIFY_ERROR(PLATFORM_FAILURE); 1538 NOTIFY_ERROR(PLATFORM_FAILURE);
1538 return false; 1539 return false;
1539 } 1540 }
1540 device_poll_thread_.message_loop()->PostTask( 1541 device_poll_thread_.message_loop()->PostTask(
1541 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::DevicePollTask, 1542 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::DevicePollTask,
1542 base::Unretained(this), 0)); 1543 base::Unretained(this), 0));
1543 1544
1544 return true; 1545 return true;
1545 } 1546 }
1546 1547
1547 bool V4L2VideoDecodeAccelerator::StopDevicePoll() { 1548 bool V4L2VideoDecodeAccelerator::StopDevicePoll() {
1548 DVLOG(3) << "StopDevicePoll()"; 1549 DVLOG(3) << "StopDevicePoll()";
1549 1550
1550 if (!device_poll_thread_.IsRunning()) 1551 if (!device_poll_thread_.IsRunning())
1551 return true; 1552 return true;
1552 1553
1553 if (decoder_thread_.IsRunning()) 1554 if (decoder_thread_.IsRunning())
1554 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1555 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1555 1556
1556 // Signal the DevicePollTask() to stop, and stop the device poll thread. 1557 // Signal the DevicePollTask() to stop, and stop the device poll thread.
1557 if (!device_->SetDevicePollInterrupt()) { 1558 if (!device_->SetDevicePollInterrupt()) {
1558 PLOG(ERROR) << "SetDevicePollInterrupt(): failed"; 1559 PLOG(ERROR) << "SetDevicePollInterrupt(): failed";
1559 NOTIFY_ERROR(PLATFORM_FAILURE); 1560 NOTIFY_ERROR(PLATFORM_FAILURE);
1560 return false; 1561 return false;
1561 } 1562 }
1562 device_poll_thread_.Stop(); 1563 device_poll_thread_.Stop();
1563 // Clear the interrupt now, to be sure. 1564 // Clear the interrupt now, to be sure.
1564 if (!device_->ClearDevicePollInterrupt()) { 1565 if (!device_->ClearDevicePollInterrupt()) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 input_buffer_map_[i].at_device = false; 1612 input_buffer_map_[i].at_device = false;
1612 input_buffer_map_[i].bytes_used = 0; 1613 input_buffer_map_[i].bytes_used = 0;
1613 input_buffer_map_[i].input_id = -1; 1614 input_buffer_map_[i].input_id = -1;
1614 } 1615 }
1615 input_buffer_queued_count_ = 0; 1616 input_buffer_queued_count_ = 0;
1616 1617
1617 return true; 1618 return true;
1618 } 1619 }
1619 1620
1620 void V4L2VideoDecodeAccelerator::StartResolutionChange() { 1621 void V4L2VideoDecodeAccelerator::StartResolutionChange() {
1621 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1622 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1622 DCHECK_NE(decoder_state_, kUninitialized); 1623 DCHECK_NE(decoder_state_, kUninitialized);
1623 DCHECK_NE(decoder_state_, kResetting); 1624 DCHECK_NE(decoder_state_, kResetting);
1624 1625
1625 DVLOG(3) << "Initiate resolution change"; 1626 DVLOG(3) << "Initiate resolution change";
1626 1627
1627 if (!(StopDevicePoll() && StopOutputStream())) 1628 if (!(StopDevicePoll() && StopOutputStream()))
1628 return; 1629 return;
1629 1630
1630 decoder_state_ = kChangingResolution; 1631 decoder_state_ = kChangingResolution;
1631 1632
1632 if (!image_processor_bitstream_buffer_ids_.empty()) { 1633 if (!image_processor_bitstream_buffer_ids_.empty()) {
1633 DVLOG(3) << "Wait image processor to finish before destroying buffers."; 1634 DVLOG(3) << "Wait image processor to finish before destroying buffers.";
1634 return; 1635 return;
1635 } 1636 }
1636 1637
1637 // Post a task to clean up buffers on child thread. This will also ensure 1638 // Post a task to clean up buffers on child thread. This will also ensure
1638 // that we won't accept ReusePictureBuffer() anymore after that. 1639 // that we won't accept ReusePictureBuffer() anymore after that.
1639 child_task_runner_->PostTask( 1640 child_task_runner_->PostTask(
1640 FROM_HERE, 1641 FROM_HERE,
1641 base::Bind(&V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers, 1642 base::Bind(&V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers,
1642 weak_this_)); 1643 weak_this_));
1643 } 1644 }
1644 1645
1645 void V4L2VideoDecodeAccelerator::FinishResolutionChange() { 1646 void V4L2VideoDecodeAccelerator::FinishResolutionChange() {
1646 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1647 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1647 DCHECK_EQ(decoder_state_, kChangingResolution); 1648 DCHECK_EQ(decoder_state_, kChangingResolution);
1648 DVLOG(3) << "FinishResolutionChange()"; 1649 DVLOG(3) << "FinishResolutionChange()";
1649 1650
1650 if (decoder_state_ == kError) { 1651 if (decoder_state_ == kError) {
1651 DVLOG(2) << "FinishResolutionChange(): early out: kError state"; 1652 DVLOG(2) << "FinishResolutionChange(): early out: kError state";
1652 return; 1653 return;
1653 } 1654 }
1654 1655
1655 struct v4l2_format format; 1656 struct v4l2_format format;
1656 bool again; 1657 bool again;
(...skipping 21 matching lines...) Expand all
1678 1679
1679 if (!StartDevicePoll()) 1680 if (!StartDevicePoll())
1680 return; 1681 return;
1681 1682
1682 Enqueue(); 1683 Enqueue();
1683 ScheduleDecodeBufferTaskIfNeeded(); 1684 ScheduleDecodeBufferTaskIfNeeded();
1684 } 1685 }
1685 1686
1686 void V4L2VideoDecodeAccelerator::DevicePollTask(bool poll_device) { 1687 void V4L2VideoDecodeAccelerator::DevicePollTask(bool poll_device) {
1687 DVLOG(3) << "DevicePollTask()"; 1688 DVLOG(3) << "DevicePollTask()";
1688 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); 1689 DCHECK(device_poll_thread_.task_runner()->BelongsToCurrentThread());
1689 TRACE_EVENT0("Video Decoder", "V4L2VDA::DevicePollTask"); 1690 TRACE_EVENT0("Video Decoder", "V4L2VDA::DevicePollTask");
1690 1691
1691 bool event_pending = false; 1692 bool event_pending = false;
1692 1693
1693 if (!device_->Poll(poll_device, &event_pending)) { 1694 if (!device_->Poll(poll_device, &event_pending)) {
1694 NOTIFY_ERROR(PLATFORM_FAILURE); 1695 NOTIFY_ERROR(PLATFORM_FAILURE);
1695 return; 1696 return;
1696 } 1697 }
1697 1698
1698 // All processing should happen on ServiceDeviceTask(), since we shouldn't 1699 // All processing should happen on ServiceDeviceTask(), since we shouldn't
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 // not allow doing so before that. 1734 // not allow doing so before that.
1734 if (decoder_state_ != kError && decoder_state_ != kUninitialized) 1735 if (decoder_state_ != kError && decoder_state_ != kUninitialized)
1735 NotifyError(error); 1736 NotifyError(error);
1736 1737
1737 decoder_state_ = kError; 1738 decoder_state_ = kError;
1738 } 1739 }
1739 1740
1740 bool V4L2VideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format, 1741 bool V4L2VideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format,
1741 gfx::Size* visible_size, 1742 gfx::Size* visible_size,
1742 bool* again) { 1743 bool* again) {
1743 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1744 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1744 1745
1745 *again = false; 1746 *again = false;
1746 memset(format, 0, sizeof(*format)); 1747 memset(format, 0, sizeof(*format));
1747 format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1748 format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1748 if (device_->Ioctl(VIDIOC_G_FMT, format) != 0) { 1749 if (device_->Ioctl(VIDIOC_G_FMT, format) != 0) {
1749 if (errno == EINVAL) { 1750 if (errno == EINVAL) {
1750 // EINVAL means we haven't seen sufficient stream to decode the format. 1751 // EINVAL means we haven't seen sufficient stream to decode the format.
1751 *again = true; 1752 *again = true;
1752 return true; 1753 return true;
1753 } else { 1754 } else {
(...skipping 12 matching lines...) Expand all
1766 gfx::Size coded_size(format->fmt.pix_mp.width, format->fmt.pix_mp.height); 1767 gfx::Size coded_size(format->fmt.pix_mp.width, format->fmt.pix_mp.height);
1767 if (visible_size != nullptr) 1768 if (visible_size != nullptr)
1768 *visible_size = GetVisibleSize(coded_size); 1769 *visible_size = GetVisibleSize(coded_size);
1769 1770
1770 return true; 1771 return true;
1771 } 1772 }
1772 1773
1773 bool V4L2VideoDecodeAccelerator::CreateBuffersForFormat( 1774 bool V4L2VideoDecodeAccelerator::CreateBuffersForFormat(
1774 const struct v4l2_format& format, 1775 const struct v4l2_format& format,
1775 const gfx::Size& visible_size) { 1776 const gfx::Size& visible_size) {
1776 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1777 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1777 output_planes_count_ = format.fmt.pix_mp.num_planes; 1778 output_planes_count_ = format.fmt.pix_mp.num_planes;
1778 coded_size_.SetSize(format.fmt.pix_mp.width, format.fmt.pix_mp.height); 1779 coded_size_.SetSize(format.fmt.pix_mp.width, format.fmt.pix_mp.height);
1779 visible_size_ = visible_size; 1780 visible_size_ = visible_size;
1780 if (image_processor_device_) { 1781 if (image_processor_device_) {
1781 V4L2ImageProcessor processor(image_processor_device_); 1782 V4L2ImageProcessor processor(image_processor_device_);
1782 egl_image_size_ = visible_size_; 1783 egl_image_size_ = visible_size_;
1783 egl_image_planes_count_ = 0; 1784 egl_image_planes_count_ = 0;
1784 if (!processor.TryOutputFormat(egl_image_format_fourcc_, &egl_image_size_, 1785 if (!processor.TryOutputFormat(egl_image_format_fourcc_, &egl_image_size_,
1785 &egl_image_planes_count_)) { 1786 &egl_image_planes_count_)) {
1786 LOG(ERROR) << "Fail to get output size and plane count of processor"; 1787 LOG(ERROR) << "Fail to get output size and plane count of processor";
1787 return false; 1788 return false;
1788 } 1789 }
1789 } else { 1790 } else {
1790 egl_image_size_ = coded_size_; 1791 egl_image_size_ = coded_size_;
1791 egl_image_planes_count_ = output_planes_count_; 1792 egl_image_planes_count_ = output_planes_count_;
1792 } 1793 }
1793 DVLOG(3) << "CreateBuffersForFormat(): new resolution: " 1794 DVLOG(3) << "CreateBuffersForFormat(): new resolution: "
1794 << coded_size_.ToString() 1795 << coded_size_.ToString()
1795 << ", visible size: " << visible_size_.ToString() 1796 << ", visible size: " << visible_size_.ToString()
1796 << ", EGLImage size: " << egl_image_size_.ToString(); 1797 << ", EGLImage size: " << egl_image_size_.ToString();
1797 1798
1798 return CreateOutputBuffers(); 1799 return CreateOutputBuffers();
1799 } 1800 }
1800 1801
1801 gfx::Size V4L2VideoDecodeAccelerator::GetVisibleSize( 1802 gfx::Size V4L2VideoDecodeAccelerator::GetVisibleSize(
1802 const gfx::Size& coded_size) { 1803 const gfx::Size& coded_size) {
1803 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1804 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1804 1805
1805 struct v4l2_crop crop_arg; 1806 struct v4l2_crop crop_arg;
1806 memset(&crop_arg, 0, sizeof(crop_arg)); 1807 memset(&crop_arg, 0, sizeof(crop_arg));
1807 crop_arg.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1808 crop_arg.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1808 1809
1809 if (device_->Ioctl(VIDIOC_G_CROP, &crop_arg) != 0) { 1810 if (device_->Ioctl(VIDIOC_G_CROP, &crop_arg) != 0) {
1810 PLOG(ERROR) << "GetVisibleSize(): ioctl() VIDIOC_G_CROP failed"; 1811 PLOG(ERROR) << "GetVisibleSize(): ioctl() VIDIOC_G_CROP failed";
1811 return coded_size; 1812 return coded_size;
1812 } 1813 }
1813 1814
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 } 2142 }
2142 2143
2143 // Finish resolution change on decoder thread. 2144 // Finish resolution change on decoder thread.
2144 decoder_thread_.message_loop()->PostTask( 2145 decoder_thread_.message_loop()->PostTask(
2145 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::FinishResolutionChange, 2146 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::FinishResolutionChange,
2146 base::Unretained(this))); 2147 base::Unretained(this)));
2147 } 2148 }
2148 2149
2149 void V4L2VideoDecodeAccelerator::SendPictureReady() { 2150 void V4L2VideoDecodeAccelerator::SendPictureReady() {
2150 DVLOG(3) << "SendPictureReady()"; 2151 DVLOG(3) << "SendPictureReady()";
2151 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 2152 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
2152 bool resetting_or_flushing = 2153 bool resetting_or_flushing =
2153 (decoder_state_ == kResetting || decoder_flushing_); 2154 (decoder_state_ == kResetting || decoder_flushing_);
2154 while (pending_picture_ready_.size() > 0) { 2155 while (pending_picture_ready_.size() > 0) {
2155 bool cleared = pending_picture_ready_.front().cleared; 2156 bool cleared = pending_picture_ready_.front().cleared;
2156 const Picture& picture = pending_picture_ready_.front().picture; 2157 const Picture& picture = pending_picture_ready_.front().picture;
2157 if (cleared && picture_clearing_count_ == 0) { 2158 if (cleared && picture_clearing_count_ == 0) {
2158 // This picture is cleared. It can be posted to a thread different than 2159 // This picture is cleared. It can be posted to a thread different than
2159 // the main GPU thread to reduce latency. This should be the case after 2160 // the main GPU thread to reduce latency. This should be the case after
2160 // all pictures are cleared at the beginning. 2161 // all pictures are cleared at the beginning.
2161 decode_task_runner_->PostTask( 2162 decode_task_runner_->PostTask(
(...skipping 22 matching lines...) Expand all
2184 // This picture is cleared. But some pictures are about to be cleared on 2185 // This picture is cleared. But some pictures are about to be cleared on
2185 // the child thread. To preserve the order, do not send this until those 2186 // the child thread. To preserve the order, do not send this until those
2186 // pictures are cleared. 2187 // pictures are cleared.
2187 break; 2188 break;
2188 } 2189 }
2189 } 2190 }
2190 } 2191 }
2191 2192
2192 void V4L2VideoDecodeAccelerator::PictureCleared() { 2193 void V4L2VideoDecodeAccelerator::PictureCleared() {
2193 DVLOG(3) << "PictureCleared(). clearing count=" << picture_clearing_count_; 2194 DVLOG(3) << "PictureCleared(). clearing count=" << picture_clearing_count_;
2194 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 2195 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
2195 DCHECK_GT(picture_clearing_count_, 0); 2196 DCHECK_GT(picture_clearing_count_, 0);
2196 picture_clearing_count_--; 2197 picture_clearing_count_--;
2197 SendPictureReady(); 2198 SendPictureReady();
2198 } 2199 }
2199 2200
2200 void V4L2VideoDecodeAccelerator::FrameProcessed(int32_t bitstream_buffer_id, 2201 void V4L2VideoDecodeAccelerator::FrameProcessed(int32_t bitstream_buffer_id,
2201 int output_buffer_index) { 2202 int output_buffer_index) {
2202 DVLOG(3) << __func__ << ": output_buffer_index=" << output_buffer_index 2203 DVLOG(3) << __func__ << ": output_buffer_index=" << output_buffer_index
2203 << ", bitstream_buffer_id=" << bitstream_buffer_id; 2204 << ", bitstream_buffer_id=" << bitstream_buffer_id;
2204 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 2205 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
2205 DCHECK_GE(output_buffer_index, 0); 2206 DCHECK_GE(output_buffer_index, 0);
2206 DCHECK_LT(output_buffer_index, static_cast<int>(output_buffer_map_.size())); 2207 DCHECK_LT(output_buffer_index, static_cast<int>(output_buffer_map_.size()));
2207 2208
2208 OutputRecord& output_record = output_buffer_map_[output_buffer_index]; 2209 OutputRecord& output_record = output_buffer_map_[output_buffer_index];
2209 DCHECK_EQ(output_record.state, kAtProcessor); 2210 DCHECK_EQ(output_record.state, kAtProcessor);
2210 if (!image_processor_bitstream_buffer_ids_.empty() && 2211 if (!image_processor_bitstream_buffer_ids_.empty() &&
2211 image_processor_bitstream_buffer_ids_.front() == bitstream_buffer_id) { 2212 image_processor_bitstream_buffer_ids_.front() == bitstream_buffer_id) {
2212 DVLOG(3) << __func__ << ": picture_id=" << output_record.picture_id; 2213 DVLOG(3) << __func__ << ": picture_id=" << output_record.picture_id;
2213 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); 2214 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR);
2214 DCHECK_NE(output_record.picture_id, -1); 2215 DCHECK_NE(output_record.picture_id, -1);
(...skipping 20 matching lines...) Expand all
2235 Enqueue(); 2236 Enqueue();
2236 } 2237 }
2237 } 2238 }
2238 2239
2239 void V4L2VideoDecodeAccelerator::ImageProcessorError() { 2240 void V4L2VideoDecodeAccelerator::ImageProcessorError() {
2240 LOG(ERROR) << "Image processor error"; 2241 LOG(ERROR) << "Image processor error";
2241 NOTIFY_ERROR(PLATFORM_FAILURE); 2242 NOTIFY_ERROR(PLATFORM_FAILURE);
2242 } 2243 }
2243 2244
2244 } // namespace media 2245 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698