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

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: CR Created 4 years, 5 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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 if (!device) 529 if (!device)
529 return SupportedProfiles(); 530 return SupportedProfiles();
530 531
531 return device->GetSupportedDecodeProfiles(arraysize(supported_input_fourccs_), 532 return device->GetSupportedDecodeProfiles(arraysize(supported_input_fourccs_),
532 supported_input_fourccs_); 533 supported_input_fourccs_);
533 } 534 }
534 535
535 void V4L2VideoDecodeAccelerator::DecodeTask( 536 void V4L2VideoDecodeAccelerator::DecodeTask(
536 const BitstreamBuffer& bitstream_buffer) { 537 const BitstreamBuffer& bitstream_buffer) {
537 DVLOGF(3) << "input_id=" << bitstream_buffer.id(); 538 DVLOGF(3) << "input_id=" << bitstream_buffer.id();
538 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 539 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
539 DCHECK_NE(decoder_state_, kUninitialized); 540 DCHECK_NE(decoder_state_, kUninitialized);
540 TRACE_EVENT1("Video Decoder", "V4L2VDA::DecodeTask", "input_id", 541 TRACE_EVENT1("Video Decoder", "V4L2VDA::DecodeTask", "input_id",
541 bitstream_buffer.id()); 542 bitstream_buffer.id());
542 543
543 std::unique_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( 544 std::unique_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef(
544 decode_client_, decode_task_runner_, 545 decode_client_, decode_task_runner_,
545 std::unique_ptr<SharedMemoryRegion>( 546 std::unique_ptr<SharedMemoryRegion>(
546 new SharedMemoryRegion(bitstream_buffer, true)), 547 new SharedMemoryRegion(bitstream_buffer, true)),
547 bitstream_buffer.id())); 548 bitstream_buffer.id()));
548 549
(...skipping 22 matching lines...) Expand all
571 } 572 }
572 573
573 decoder_input_queue_.push( 574 decoder_input_queue_.push(
574 linked_ptr<BitstreamBufferRef>(bitstream_record.release())); 575 linked_ptr<BitstreamBufferRef>(bitstream_record.release()));
575 decoder_decode_buffer_tasks_scheduled_++; 576 decoder_decode_buffer_tasks_scheduled_++;
576 DecodeBufferTask(); 577 DecodeBufferTask();
577 } 578 }
578 579
579 void V4L2VideoDecodeAccelerator::DecodeBufferTask() { 580 void V4L2VideoDecodeAccelerator::DecodeBufferTask() {
580 DVLOGF(3); 581 DVLOGF(3);
581 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 582 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
582 DCHECK_NE(decoder_state_, kUninitialized); 583 DCHECK_NE(decoder_state_, kUninitialized);
583 TRACE_EVENT0("Video Decoder", "V4L2VDA::DecodeBufferTask"); 584 TRACE_EVENT0("Video Decoder", "V4L2VDA::DecodeBufferTask");
584 585
585 decoder_decode_buffer_tasks_scheduled_--; 586 decoder_decode_buffer_tasks_scheduled_--;
586 587
587 if (decoder_state_ == kResetting) { 588 if (decoder_state_ == kResetting) {
588 DVLOGF(2) << "early out: kResetting state"; 589 DVLOGF(2) << "early out: kResetting state";
589 return; 590 return;
590 } else if (decoder_state_ == kError) { 591 } else if (decoder_state_ == kError) {
591 DVLOGF(2) << "early out: kError state"; 592 DVLOGF(2) << "early out: kError state";
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 DCHECK_LE(video_profile_, VP9PROFILE_MAX); 774 DCHECK_LE(video_profile_, VP9PROFILE_MAX);
774 // For VP8/9, we can just dump the entire buffer. No fragmentation needed, 775 // For VP8/9, we can just dump the entire buffer. No fragmentation needed,
775 // and we never return a partial frame. 776 // and we never return a partial frame.
776 *endpos = size; 777 *endpos = size;
777 decoder_partial_frame_pending_ = false; 778 decoder_partial_frame_pending_ = false;
778 return true; 779 return true;
779 } 780 }
780 } 781 }
781 782
782 void V4L2VideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { 783 void V4L2VideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() {
783 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 784 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
784 785
785 // If we're behind on tasks, schedule another one. 786 // If we're behind on tasks, schedule another one.
786 int buffers_to_decode = decoder_input_queue_.size(); 787 int buffers_to_decode = decoder_input_queue_.size();
787 if (decoder_current_bitstream_buffer_ != NULL) 788 if (decoder_current_bitstream_buffer_ != NULL)
788 buffers_to_decode++; 789 buffers_to_decode++;
789 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { 790 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) {
790 decoder_decode_buffer_tasks_scheduled_++; 791 decoder_decode_buffer_tasks_scheduled_++;
791 decoder_thread_.message_loop()->PostTask( 792 decoder_thread_.message_loop()->PostTask(
792 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::DecodeBufferTask, 793 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::DecodeBufferTask,
793 base::Unretained(this))); 794 base::Unretained(this)));
794 } 795 }
795 } 796 }
796 797
797 bool V4L2VideoDecodeAccelerator::DecodeBufferInitial(const void* data, 798 bool V4L2VideoDecodeAccelerator::DecodeBufferInitial(const void* data,
798 size_t size, 799 size_t size,
799 size_t* endpos) { 800 size_t* endpos) {
800 DVLOGF(3) << "data=" << data << ", size=" << size; 801 DVLOGF(3) << "data=" << data << ", size=" << size;
801 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 802 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
802 DCHECK_NE(decoder_state_, kUninitialized); 803 DCHECK_NE(decoder_state_, kUninitialized);
803 DCHECK_NE(decoder_state_, kDecoding); 804 DCHECK_NE(decoder_state_, kDecoding);
804 // Initial decode. We haven't been able to get output stream format info yet. 805 // Initial decode. We haven't been able to get output stream format info yet.
805 // Get it, and start decoding. 806 // Get it, and start decoding.
806 807
807 // Copy in and send to HW. 808 // Copy in and send to HW.
808 if (!AppendToInputFrame(data, size)) 809 if (!AppendToInputFrame(data, size))
809 return false; 810 return false;
810 811
811 // If we only have a partial frame, don't flush and process yet. 812 // If we only have a partial frame, don't flush and process yet.
(...skipping 29 matching lines...) Expand all
841 } 842 }
842 843
843 decoder_state_ = kDecoding; 844 decoder_state_ = kDecoding;
844 ScheduleDecodeBufferTaskIfNeeded(); 845 ScheduleDecodeBufferTaskIfNeeded();
845 return true; 846 return true;
846 } 847 }
847 848
848 bool V4L2VideoDecodeAccelerator::DecodeBufferContinue(const void* data, 849 bool V4L2VideoDecodeAccelerator::DecodeBufferContinue(const void* data,
849 size_t size) { 850 size_t size) {
850 DVLOGF(3) << "data=" << data << ", size=" << size; 851 DVLOGF(3) << "data=" << data << ", size=" << size;
851 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 852 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
852 DCHECK_EQ(decoder_state_, kDecoding); 853 DCHECK_EQ(decoder_state_, kDecoding);
853 854
854 // Both of these calls will set kError state if they fail. 855 // Both of these calls will set kError state if they fail.
855 // Only flush the frame if it's complete. 856 // Only flush the frame if it's complete.
856 return (AppendToInputFrame(data, size) && 857 return (AppendToInputFrame(data, size) &&
857 (decoder_partial_frame_pending_ || FlushInputFrame())); 858 (decoder_partial_frame_pending_ || FlushInputFrame()));
858 } 859 }
859 860
860 bool V4L2VideoDecodeAccelerator::AppendToInputFrame(const void* data, 861 bool V4L2VideoDecodeAccelerator::AppendToInputFrame(const void* data,
861 size_t size) { 862 size_t size) {
862 DVLOGF(3); 863 DVLOGF(3);
863 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 864 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
864 DCHECK_NE(decoder_state_, kUninitialized); 865 DCHECK_NE(decoder_state_, kUninitialized);
865 DCHECK_NE(decoder_state_, kResetting); 866 DCHECK_NE(decoder_state_, kResetting);
866 DCHECK_NE(decoder_state_, kError); 867 DCHECK_NE(decoder_state_, kError);
867 // This routine can handle data == NULL and size == 0, which occurs when 868 // This routine can handle data == NULL and size == 0, which occurs when
868 // we queue an empty buffer for the purposes of flushing the pipe. 869 // we queue an empty buffer for the purposes of flushing the pipe.
869 870
870 // Flush if we're too big 871 // Flush if we're too big
871 if (decoder_current_input_buffer_ != -1) { 872 if (decoder_current_input_buffer_ != -1) {
872 InputRecord& input_record = 873 InputRecord& input_record =
873 input_buffer_map_[decoder_current_input_buffer_]; 874 input_buffer_map_[decoder_current_input_buffer_];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 memcpy(reinterpret_cast<uint8_t*>(input_record.address) + 918 memcpy(reinterpret_cast<uint8_t*>(input_record.address) +
918 input_record.bytes_used, 919 input_record.bytes_used,
919 data, size); 920 data, size);
920 input_record.bytes_used += size; 921 input_record.bytes_used += size;
921 922
922 return true; 923 return true;
923 } 924 }
924 925
925 bool V4L2VideoDecodeAccelerator::FlushInputFrame() { 926 bool V4L2VideoDecodeAccelerator::FlushInputFrame() {
926 DVLOGF(3); 927 DVLOGF(3);
927 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 928 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
928 DCHECK_NE(decoder_state_, kUninitialized); 929 DCHECK_NE(decoder_state_, kUninitialized);
929 DCHECK_NE(decoder_state_, kResetting); 930 DCHECK_NE(decoder_state_, kResetting);
930 DCHECK_NE(decoder_state_, kError); 931 DCHECK_NE(decoder_state_, kError);
931 932
932 if (decoder_current_input_buffer_ == -1) 933 if (decoder_current_input_buffer_ == -1)
933 return true; 934 return true;
934 935
935 InputRecord& input_record = input_buffer_map_[decoder_current_input_buffer_]; 936 InputRecord& input_record = input_buffer_map_[decoder_current_input_buffer_];
936 DCHECK_NE(input_record.input_id, -1); 937 DCHECK_NE(input_record.input_id, -1);
937 DCHECK(input_record.input_id != kFlushBufferId || 938 DCHECK(input_record.input_id != kFlushBufferId ||
(...skipping 15 matching lines...) Expand all
953 decoder_current_input_buffer_ = -1; 954 decoder_current_input_buffer_ = -1;
954 DVLOGF(3) << "submitting input_id=" << input_record.input_id; 955 DVLOGF(3) << "submitting input_id=" << input_record.input_id;
955 // Enqueue once since there's new available input for it. 956 // Enqueue once since there's new available input for it.
956 Enqueue(); 957 Enqueue();
957 958
958 return (decoder_state_ != kError); 959 return (decoder_state_ != kError);
959 } 960 }
960 961
961 void V4L2VideoDecodeAccelerator::ServiceDeviceTask(bool event_pending) { 962 void V4L2VideoDecodeAccelerator::ServiceDeviceTask(bool event_pending) {
962 DVLOGF(3); 963 DVLOGF(3);
963 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 964 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
964 DCHECK_NE(decoder_state_, kUninitialized); 965 DCHECK_NE(decoder_state_, kUninitialized);
965 TRACE_EVENT0("Video Decoder", "V4L2VDA::ServiceDeviceTask"); 966 TRACE_EVENT0("Video Decoder", "V4L2VDA::ServiceDeviceTask");
966 967
967 if (decoder_state_ == kResetting) { 968 if (decoder_state_ == kResetting) {
968 DVLOGF(2) << "early out: kResetting state"; 969 DVLOGF(2) << "early out: kResetting state";
969 return; 970 return;
970 } else if (decoder_state_ == kError) { 971 } else if (decoder_state_ == kError) {
971 DVLOGF(2) << "early out: kError state"; 972 DVLOGF(2) << "early out: kError state";
972 return; 973 return;
973 } else if (decoder_state_ == kChangingResolution) { 974 } else if (decoder_state_ == kChangingResolution) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 << image_processor_bitstream_buffer_ids_.size() << "] => CLIENT[" 1018 << image_processor_bitstream_buffer_ids_.size() << "] => CLIENT["
1018 << decoder_frames_at_client_ << "]"; 1019 << decoder_frames_at_client_ << "]";
1019 1020
1020 ScheduleDecodeBufferTaskIfNeeded(); 1021 ScheduleDecodeBufferTaskIfNeeded();
1021 if (resolution_change_pending) 1022 if (resolution_change_pending)
1022 StartResolutionChange(); 1023 StartResolutionChange();
1023 } 1024 }
1024 1025
1025 void V4L2VideoDecodeAccelerator::Enqueue() { 1026 void V4L2VideoDecodeAccelerator::Enqueue() {
1026 DVLOGF(3); 1027 DVLOGF(3);
1027 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1028 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1028 DCHECK_NE(decoder_state_, kUninitialized); 1029 DCHECK_NE(decoder_state_, kUninitialized);
1029 TRACE_EVENT0("Video Decoder", "V4L2VDA::Enqueue"); 1030 TRACE_EVENT0("Video Decoder", "V4L2VDA::Enqueue");
1030 1031
1031 // Drain the pipe of completed decode buffers. 1032 // Drain the pipe of completed decode buffers.
1032 const int old_inputs_queued = input_buffer_queued_count_; 1033 const int old_inputs_queued = input_buffer_queued_count_;
1033 while (!input_ready_queue_.empty()) { 1034 while (!input_ready_queue_.empty()) {
1034 if (!EnqueueInputRecord()) 1035 if (!EnqueueInputRecord())
1035 return; 1036 return;
1036 } 1037 }
1037 if (old_inputs_queued == 0 && input_buffer_queued_count_ != 0) { 1038 if (old_inputs_queued == 0 && input_buffer_queued_count_ != 0) {
(...skipping 29 matching lines...) Expand all
1067 // Start VIDIOC_STREAMON if we haven't yet. 1068 // Start VIDIOC_STREAMON if we haven't yet.
1068 if (!output_streamon_) { 1069 if (!output_streamon_) {
1069 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1070 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1070 IOCTL_OR_ERROR_RETURN(VIDIOC_STREAMON, &type); 1071 IOCTL_OR_ERROR_RETURN(VIDIOC_STREAMON, &type);
1071 output_streamon_ = true; 1072 output_streamon_ = true;
1072 } 1073 }
1073 } 1074 }
1074 } 1075 }
1075 1076
1076 bool V4L2VideoDecodeAccelerator::DequeueResolutionChangeEvent() { 1077 bool V4L2VideoDecodeAccelerator::DequeueResolutionChangeEvent() {
1077 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1078 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1078 DCHECK_NE(decoder_state_, kUninitialized); 1079 DCHECK_NE(decoder_state_, kUninitialized);
1079 DVLOGF(3); 1080 DVLOGF(3);
1080 1081
1081 struct v4l2_event ev; 1082 struct v4l2_event ev;
1082 memset(&ev, 0, sizeof(ev)); 1083 memset(&ev, 0, sizeof(ev));
1083 1084
1084 while (device_->Ioctl(VIDIOC_DQEVENT, &ev) == 0) { 1085 while (device_->Ioctl(VIDIOC_DQEVENT, &ev) == 0) {
1085 if (ev.type == V4L2_EVENT_SOURCE_CHANGE) { 1086 if (ev.type == V4L2_EVENT_SOURCE_CHANGE) {
1086 if (ev.u.src_change.changes & V4L2_EVENT_SRC_CH_RESOLUTION) { 1087 if (ev.u.src_change.changes & V4L2_EVENT_SRC_CH_RESOLUTION) {
1087 DVLOGF(3) << "got resolution change event."; 1088 DVLOGF(3) << "got resolution change event.";
1088 return true; 1089 return true;
1089 } 1090 }
1090 } else { 1091 } else {
1091 LOGF(ERROR) << "got an event (" << ev.type 1092 LOGF(ERROR) << "got an event (" << ev.type
1092 << ") we haven't subscribed to."; 1093 << ") we haven't subscribed to.";
1093 } 1094 }
1094 } 1095 }
1095 return false; 1096 return false;
1096 } 1097 }
1097 1098
1098 void V4L2VideoDecodeAccelerator::Dequeue() { 1099 void V4L2VideoDecodeAccelerator::Dequeue() {
1099 DVLOGF(3); 1100 DVLOGF(3);
1100 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1101 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1101 DCHECK_NE(decoder_state_, kUninitialized); 1102 DCHECK_NE(decoder_state_, kUninitialized);
1102 TRACE_EVENT0("Video Decoder", "V4L2VDA::Dequeue"); 1103 TRACE_EVENT0("Video Decoder", "V4L2VDA::Dequeue");
1103 1104
1104 // Dequeue completed input (VIDEO_OUTPUT) buffers, and recycle to the free 1105 // Dequeue completed input (VIDEO_OUTPUT) buffers, and recycle to the free
1105 // list. 1106 // list.
1106 while (input_buffer_queued_count_ > 0) { 1107 while (input_buffer_queued_count_ > 0) {
1107 DCHECK(input_streamon_); 1108 DCHECK(input_streamon_);
1108 struct v4l2_buffer dqbuf; 1109 struct v4l2_buffer dqbuf;
1109 struct v4l2_plane planes[1]; 1110 struct v4l2_plane planes[1];
1110 memset(&dqbuf, 0, sizeof(dqbuf)); 1111 memset(&dqbuf, 0, sizeof(dqbuf));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 free_output_buffers_.pop(); 1275 free_output_buffers_.pop();
1275 output_record.state = kAtDevice; 1276 output_record.state = kAtDevice;
1276 output_buffer_queued_count_++; 1277 output_buffer_queued_count_++;
1277 return true; 1278 return true;
1278 } 1279 }
1279 1280
1280 void V4L2VideoDecodeAccelerator::ReusePictureBufferTask( 1281 void V4L2VideoDecodeAccelerator::ReusePictureBufferTask(
1281 int32_t picture_buffer_id, 1282 int32_t picture_buffer_id,
1282 std::unique_ptr<EGLSyncKHRRef> egl_sync_ref) { 1283 std::unique_ptr<EGLSyncKHRRef> egl_sync_ref) {
1283 DVLOGF(3) << "picture_buffer_id=" << picture_buffer_id; 1284 DVLOGF(3) << "picture_buffer_id=" << 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 DVLOGF(2) << "early out: kError state"; 1290 DVLOGF(2) << "early out: kError state";
1290 return; 1291 return;
1291 } 1292 }
1292 1293
1293 if (decoder_state_ == kChangingResolution) { 1294 if (decoder_state_ == kChangingResolution) {
1294 DVLOGF(2) << "early out: kChangingResolution"; 1295 DVLOGF(2) << "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 DVLOGF(3); 1334 DVLOGF(3);
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 DVLOGF(3) << "returning flush"; 1341 DVLOGF(3) << "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 DVLOGF(2) << "early out: kError state"; 1346 DVLOGF(2) << "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 DVLOGF(3) << "returning flush"; 1403 DVLOGF(3) << "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 DVLOGF(3); 1412 DVLOGF(3);
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 DVLOGF(2) << "early out: kError state"; 1417 DVLOGF(2) << "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 DVLOGF(3); 1472 DVLOGF(3);
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 DVLOGF(2) << "early out: kError state"; 1477 DVLOGF(2) << "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 DVLOGF(3); 1531 DVLOGF(3);
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 LOGF(ERROR) << "Device thread failed to start"; 1537 LOGF(ERROR) << "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 DVLOGF(3); 1549 DVLOGF(3);
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 PLOGF(ERROR) << "SetDevicePollInterrupt(): failed"; 1559 PLOGF(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 DVLOGF(3) << "Initiate resolution change"; 1626 DVLOGF(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 DVLOGF(3) << "Wait image processor to finish before destroying buffers."; 1634 DVLOGF(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 DVLOGF(3); 1649 DVLOGF(3);
1649 1650
1650 if (decoder_state_ == kError) { 1651 if (decoder_state_ == kError) {
1651 DVLOGF(2) << "early out: kError state"; 1652 DVLOGF(2) << "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 DVLOGF(3); 1688 DVLOGF(3);
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 15 matching lines...) Expand all
1714 1715
1715 if (client_) { 1716 if (client_) {
1716 client_->NotifyError(error); 1717 client_->NotifyError(error);
1717 client_ptr_factory_.reset(); 1718 client_ptr_factory_.reset();
1718 } 1719 }
1719 } 1720 }
1720 1721
1721 void V4L2VideoDecodeAccelerator::SetErrorState(Error error) { 1722 void V4L2VideoDecodeAccelerator::SetErrorState(Error error) {
1722 // We can touch decoder_state_ only if this is the decoder thread or the 1723 // We can touch decoder_state_ only if this is the decoder thread or the
1723 // decoder thread isn't running. 1724 // decoder thread isn't running.
1724 if (decoder_thread_.message_loop() != NULL && 1725 if (decoder_thread_.task_runner() &&
1725 decoder_thread_.message_loop() != base::MessageLoop::current()) { 1726 !decoder_thread_.task_runner()->BelongsToCurrentThread()) {
1726 decoder_thread_.message_loop()->PostTask( 1727 decoder_thread_.task_runner()->PostTask(
1727 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::SetErrorState, 1728 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::SetErrorState,
1728 base::Unretained(this), error)); 1729 base::Unretained(this), error));
1729 return; 1730 return;
1730 } 1731 }
1731 1732
1732 // Post NotifyError only if we are already initialized, as the API does 1733 // Post NotifyError only if we are already initialized, as the API does
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 LOGF(ERROR) << "Fail to get output size and plane count of processor"; 1787 LOGF(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 DVLOGF(3) << "new resolution: " << coded_size_.ToString() 1794 DVLOGF(3) << "new resolution: " << coded_size_.ToString()
1794 << ", visible size: " << visible_size_.ToString() 1795 << ", visible size: " << visible_size_.ToString()
1795 << ", EGLImage size: " << egl_image_size_.ToString(); 1796 << ", EGLImage size: " << egl_image_size_.ToString();
1796 1797
1797 return CreateOutputBuffers(); 1798 return CreateOutputBuffers();
1798 } 1799 }
1799 1800
1800 gfx::Size V4L2VideoDecodeAccelerator::GetVisibleSize( 1801 gfx::Size V4L2VideoDecodeAccelerator::GetVisibleSize(
1801 const gfx::Size& coded_size) { 1802 const gfx::Size& coded_size) {
1802 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1803 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
1803 1804
1804 struct v4l2_crop crop_arg; 1805 struct v4l2_crop crop_arg;
1805 memset(&crop_arg, 0, sizeof(crop_arg)); 1806 memset(&crop_arg, 0, sizeof(crop_arg));
1806 crop_arg.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1807 crop_arg.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1807 1808
1808 if (device_->Ioctl(VIDIOC_G_CROP, &crop_arg) != 0) { 1809 if (device_->Ioctl(VIDIOC_G_CROP, &crop_arg) != 0) {
1809 PLOGF(ERROR) << "ioctl() VIDIOC_G_CROP failed"; 1810 PLOGF(ERROR) << "ioctl() VIDIOC_G_CROP failed";
1810 return coded_size; 1811 return coded_size;
1811 } 1812 }
1812 1813
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 } 2139 }
2139 2140
2140 // Finish resolution change on decoder thread. 2141 // Finish resolution change on decoder thread.
2141 decoder_thread_.message_loop()->PostTask( 2142 decoder_thread_.message_loop()->PostTask(
2142 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::FinishResolutionChange, 2143 FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::FinishResolutionChange,
2143 base::Unretained(this))); 2144 base::Unretained(this)));
2144 } 2145 }
2145 2146
2146 void V4L2VideoDecodeAccelerator::SendPictureReady() { 2147 void V4L2VideoDecodeAccelerator::SendPictureReady() {
2147 DVLOGF(3); 2148 DVLOGF(3);
2148 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 2149 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
2149 bool resetting_or_flushing = 2150 bool resetting_or_flushing =
2150 (decoder_state_ == kResetting || decoder_flushing_); 2151 (decoder_state_ == kResetting || decoder_flushing_);
2151 while (pending_picture_ready_.size() > 0) { 2152 while (pending_picture_ready_.size() > 0) {
2152 bool cleared = pending_picture_ready_.front().cleared; 2153 bool cleared = pending_picture_ready_.front().cleared;
2153 const Picture& picture = pending_picture_ready_.front().picture; 2154 const Picture& picture = pending_picture_ready_.front().picture;
2154 if (cleared && picture_clearing_count_ == 0) { 2155 if (cleared && picture_clearing_count_ == 0) {
2155 // This picture is cleared. It can be posted to a thread different than 2156 // This picture is cleared. It can be posted to a thread different than
2156 // the main GPU thread to reduce latency. This should be the case after 2157 // the main GPU thread to reduce latency. This should be the case after
2157 // all pictures are cleared at the beginning. 2158 // all pictures are cleared at the beginning.
2158 decode_task_runner_->PostTask( 2159 decode_task_runner_->PostTask(
(...skipping 21 matching lines...) Expand all
2180 // This picture is cleared. But some pictures are about to be cleared on 2181 // This picture is cleared. But some pictures are about to be cleared on
2181 // the child thread. To preserve the order, do not send this until those 2182 // the child thread. To preserve the order, do not send this until those
2182 // pictures are cleared. 2183 // pictures are cleared.
2183 break; 2184 break;
2184 } 2185 }
2185 } 2186 }
2186 } 2187 }
2187 2188
2188 void V4L2VideoDecodeAccelerator::PictureCleared() { 2189 void V4L2VideoDecodeAccelerator::PictureCleared() {
2189 DVLOGF(3) << "clearing count=" << picture_clearing_count_; 2190 DVLOGF(3) << "clearing count=" << picture_clearing_count_;
2190 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 2191 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
2191 DCHECK_GT(picture_clearing_count_, 0); 2192 DCHECK_GT(picture_clearing_count_, 0);
2192 picture_clearing_count_--; 2193 picture_clearing_count_--;
2193 SendPictureReady(); 2194 SendPictureReady();
2194 } 2195 }
2195 2196
2196 void V4L2VideoDecodeAccelerator::FrameProcessed(int32_t bitstream_buffer_id, 2197 void V4L2VideoDecodeAccelerator::FrameProcessed(int32_t bitstream_buffer_id,
2197 int output_buffer_index) { 2198 int output_buffer_index) {
2198 DVLOGF(3) << "output_buffer_index=" << output_buffer_index 2199 DVLOGF(3) << "output_buffer_index=" << output_buffer_index
2199 << ", bitstream_buffer_id=" << bitstream_buffer_id; 2200 << ", bitstream_buffer_id=" << bitstream_buffer_id;
2200 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 2201 DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread());
2201 DCHECK_GE(output_buffer_index, 0); 2202 DCHECK_GE(output_buffer_index, 0);
2202 DCHECK_LT(output_buffer_index, static_cast<int>(output_buffer_map_.size())); 2203 DCHECK_LT(output_buffer_index, static_cast<int>(output_buffer_map_.size()));
2203 2204
2204 OutputRecord& output_record = output_buffer_map_[output_buffer_index]; 2205 OutputRecord& output_record = output_buffer_map_[output_buffer_index];
2205 DCHECK_EQ(output_record.state, kAtProcessor); 2206 DCHECK_EQ(output_record.state, kAtProcessor);
2206 if (!image_processor_bitstream_buffer_ids_.empty() && 2207 if (!image_processor_bitstream_buffer_ids_.empty() &&
2207 image_processor_bitstream_buffer_ids_.front() == bitstream_buffer_id) { 2208 image_processor_bitstream_buffer_ids_.front() == bitstream_buffer_id) {
2208 DVLOGF(3) << "picture_id=" << output_record.picture_id; 2209 DVLOGF(3) << "picture_id=" << output_record.picture_id;
2209 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR); 2210 DCHECK_NE(output_record.egl_image, EGL_NO_IMAGE_KHR);
2210 DCHECK_NE(output_record.picture_id, -1); 2211 DCHECK_NE(output_record.picture_id, -1);
(...skipping 20 matching lines...) Expand all
2231 Enqueue(); 2232 Enqueue();
2232 } 2233 }
2233 } 2234 }
2234 2235
2235 void V4L2VideoDecodeAccelerator::ImageProcessorError() { 2236 void V4L2VideoDecodeAccelerator::ImageProcessorError() {
2236 LOGF(ERROR) << "Image processor error"; 2237 LOGF(ERROR) << "Image processor error";
2237 NOTIFY_ERROR(PLATFORM_FAILURE); 2238 NOTIFY_ERROR(PLATFORM_FAILURE);
2238 } 2239 }
2239 2240
2240 } // namespace media 2241 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/v4l2_slice_video_decode_accelerator.cc ('k') | media/gpu/v4l2_video_encode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698