OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <dlfcn.h> | 5 #include <dlfcn.h> |
6 #include <errno.h> | 6 #include <errno.h> |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
9 #include <poll.h> | 9 #include <poll.h> |
10 #include <sys/eventfd.h> | 10 #include <sys/eventfd.h> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 do { \ | 43 do { \ |
44 if (HANDLE_EINTR(ioctl(fd, type, arg) != 0)) { \ | 44 if (HANDLE_EINTR(ioctl(fd, type, arg) != 0)) { \ |
45 DPLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \ | 45 DPLOG(ERROR) << __func__ << "(): ioctl() failed: " << #type; \ |
46 NOTIFY_ERROR(PLATFORM_FAILURE); \ | 46 NOTIFY_ERROR(PLATFORM_FAILURE); \ |
47 return false; \ | 47 return false; \ |
48 } \ | 48 } \ |
49 } while (0) | 49 } while (0) |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
53 // TODO(posciak): remove once we update linux-headers. | |
54 #ifndef V4L2_EVENT_RESOLUTION_CHANGE | |
55 #define V4L2_EVENT_RESOLUTION_CHANGE 5 | |
56 #endif | |
57 | |
53 const char kExynosMfcDevice[] = "/dev/mfc-dec"; | 58 const char kExynosMfcDevice[] = "/dev/mfc-dec"; |
54 const char kExynosGscDevice[] = "/dev/gsc1"; | 59 const char kExynosGscDevice[] = "/dev/gsc1"; |
55 const char kMaliDriver[] = "libmali.so"; | 60 const char kMaliDriver[] = "libmali.so"; |
56 | 61 |
57 typedef EGLBoolean (*MaliEglImageGetBufferExtPhandleFunc)(EGLImageKHR, EGLint*, | 62 typedef EGLBoolean (*MaliEglImageGetBufferExtPhandleFunc)(EGLImageKHR, EGLint*, |
58 void*); | 63 void*); |
59 | 64 |
60 void* libmali_handle = NULL; | 65 void* libmali_handle = NULL; |
61 MaliEglImageGetBufferExtPhandleFunc | 66 MaliEglImageGetBufferExtPhandleFunc |
62 mali_egl_image_get_buffer_ext_phandle = NULL; | 67 mali_egl_image_get_buffer_ext_phandle = NULL; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 weak_this_(base::AsWeakPtr(this)), | 210 weak_this_(base::AsWeakPtr(this)), |
206 client_ptr_factory_(client), | 211 client_ptr_factory_(client), |
207 client_(client_ptr_factory_.GetWeakPtr()), | 212 client_(client_ptr_factory_.GetWeakPtr()), |
208 decoder_thread_("ExynosDecoderThread"), | 213 decoder_thread_("ExynosDecoderThread"), |
209 decoder_state_(kUninitialized), | 214 decoder_state_(kUninitialized), |
210 decoder_delay_bitstream_buffer_id_(-1), | 215 decoder_delay_bitstream_buffer_id_(-1), |
211 decoder_current_input_buffer_(-1), | 216 decoder_current_input_buffer_(-1), |
212 decoder_decode_buffer_tasks_scheduled_(0), | 217 decoder_decode_buffer_tasks_scheduled_(0), |
213 decoder_frames_at_client_(0), | 218 decoder_frames_at_client_(0), |
214 decoder_flushing_(false), | 219 decoder_flushing_(false), |
220 resolution_change_pending_(false), | |
215 decoder_partial_frame_pending_(false), | 221 decoder_partial_frame_pending_(false), |
216 mfc_fd_(-1), | 222 mfc_fd_(-1), |
217 mfc_input_streamon_(false), | 223 mfc_input_streamon_(false), |
218 mfc_input_buffer_queued_count_(0), | 224 mfc_input_buffer_queued_count_(0), |
219 mfc_output_streamon_(false), | 225 mfc_output_streamon_(false), |
220 mfc_output_buffer_queued_count_(0), | 226 mfc_output_buffer_queued_count_(0), |
221 mfc_output_buffer_pixelformat_(0), | 227 mfc_output_buffer_pixelformat_(0), |
222 mfc_output_dpb_size_(0), | 228 mfc_output_dpb_size_(0), |
223 gsc_fd_(-1), | 229 gsc_fd_(-1), |
224 gsc_input_streamon_(false), | 230 gsc_input_streamon_(false), |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 if (!CreateMfcInputBuffers()) | 378 if (!CreateMfcInputBuffers()) |
373 return false; | 379 return false; |
374 | 380 |
375 // MFC output format has to be setup before streaming starts. | 381 // MFC output format has to be setup before streaming starts. |
376 struct v4l2_format format; | 382 struct v4l2_format format; |
377 memset(&format, 0, sizeof(format)); | 383 memset(&format, 0, sizeof(format)); |
378 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 384 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
379 format.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12MT_16X16; | 385 format.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12MT_16X16; |
380 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_S_FMT, &format); | 386 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_S_FMT, &format); |
381 | 387 |
388 // Subscribe for the resolution change event. | |
389 struct v4l2_event_subscription sub; | |
390 memset(&sub, 0, sizeof(sub)); | |
391 sub.type = V4L2_EVENT_RESOLUTION_CHANGE; | |
392 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_SUBSCRIBE_EVENT, &sub); | |
393 | |
382 // Initialize format-specific bits. | 394 // Initialize format-specific bits. |
383 if (video_profile_ >= media::H264PROFILE_MIN && | 395 if (video_profile_ >= media::H264PROFILE_MIN && |
384 video_profile_ <= media::H264PROFILE_MAX) { | 396 video_profile_ <= media::H264PROFILE_MAX) { |
385 decoder_h264_parser_.reset(new content::H264Parser()); | 397 decoder_h264_parser_.reset(new content::H264Parser()); |
386 } | 398 } |
387 | 399 |
388 if (!decoder_thread_.Start()) { | 400 if (!decoder_thread_.Start()) { |
389 DLOG(ERROR) << "Initialize(): decoder thread failed to start"; | 401 DLOG(ERROR) << "Initialize(): decoder thread failed to start"; |
390 NOTIFY_ERROR(PLATFORM_FAILURE); | 402 NOTIFY_ERROR(PLATFORM_FAILURE); |
391 return false; | 403 return false; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 TRACE_EVENT0("Video Decoder", "EVDA::DecodeBufferTask"); | 642 TRACE_EVENT0("Video Decoder", "EVDA::DecodeBufferTask"); |
631 | 643 |
632 decoder_decode_buffer_tasks_scheduled_--; | 644 decoder_decode_buffer_tasks_scheduled_--; |
633 | 645 |
634 if (decoder_state_ == kResetting) { | 646 if (decoder_state_ == kResetting) { |
635 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state"; | 647 DVLOG(2) << "DecodeBufferTask(): early out: kResetting state"; |
636 return; | 648 return; |
637 } else if (decoder_state_ == kError) { | 649 } else if (decoder_state_ == kError) { |
638 DVLOG(2) << "DecodeBufferTask(): early out: kError state"; | 650 DVLOG(2) << "DecodeBufferTask(): early out: kError state"; |
639 return; | 651 return; |
652 } else if (decoder_state_ == kChangingResolution) { | |
653 DVLOG(2) << "DecodeBufferTask(): early out: resolution change pending"; | |
654 return; | |
640 } | 655 } |
641 | 656 |
642 if (decoder_current_bitstream_buffer_ == NULL) { | 657 if (decoder_current_bitstream_buffer_ == NULL) { |
643 if (decoder_input_queue_.empty()) { | 658 if (decoder_input_queue_.empty()) { |
644 // We're waiting for a new buffer -- exit without scheduling a new task. | 659 // We're waiting for a new buffer -- exit without scheduling a new task. |
645 return; | 660 return; |
646 } | 661 } |
647 linked_ptr<BitstreamBufferRef>& buffer_ref = decoder_input_queue_.front(); | 662 linked_ptr<BitstreamBufferRef>& buffer_ref = decoder_input_queue_.front(); |
648 if (decoder_delay_bitstream_buffer_id_ == buffer_ref->input_id) { | 663 if (decoder_delay_bitstream_buffer_id_ == buffer_ref->input_id) { |
649 // We're asked to delay decoding on this and subsequent buffers. | 664 // We're asked to delay decoding on this and subsequent buffers. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 if (decoder_current_bitstream_buffer_ != NULL) | 844 if (decoder_current_bitstream_buffer_ != NULL) |
830 buffers_to_decode++; | 845 buffers_to_decode++; |
831 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { | 846 if (decoder_decode_buffer_tasks_scheduled_ < buffers_to_decode) { |
832 decoder_decode_buffer_tasks_scheduled_++; | 847 decoder_decode_buffer_tasks_scheduled_++; |
833 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 848 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
834 &ExynosVideoDecodeAccelerator::DecodeBufferTask, | 849 &ExynosVideoDecodeAccelerator::DecodeBufferTask, |
835 base::Unretained(this))); | 850 base::Unretained(this))); |
836 } | 851 } |
837 } | 852 } |
838 | 853 |
854 bool ExynosVideoDecodeAccelerator::GetFormatInfo(struct v4l2_format* format, | |
855 bool* again) { | |
856 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | |
857 | |
858 *again = false; | |
859 memset(format, 0, sizeof(*format)); | |
860 format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
861 if (ioctl(mfc_fd_, VIDIOC_G_FMT, format) != 0) { | |
sheu
2013/08/09 09:23:16
I should have probably wrapped this in HANDLE_EINT
Pawel Osciak
2013/08/09 10:22:59
Done.
| |
862 if (errno == EINVAL) { | |
863 // EINVAL means we haven't seen sufficient stream to decode the format. | |
864 *again = true; | |
865 return true; | |
866 } else { | |
867 DPLOG(ERROR) << "DecodeBufferInitial(): ioctl() failed: VIDIOC_G_FMT"; | |
868 NOTIFY_ERROR(PLATFORM_FAILURE); | |
869 return false; | |
870 } | |
871 } | |
872 | |
873 return true; | |
874 } | |
875 | |
876 bool ExynosVideoDecodeAccelerator::CreateBuffersForFormat( | |
877 const struct v4l2_format& format) { | |
878 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | |
879 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); | |
880 frame_buffer_size_.SetSize( | |
881 format.fmt.pix_mp.width, format.fmt.pix_mp.height); | |
882 mfc_output_buffer_size_[0] = format.fmt.pix_mp.plane_fmt[0].sizeimage; | |
883 mfc_output_buffer_size_[1] = format.fmt.pix_mp.plane_fmt[1].sizeimage; | |
884 mfc_output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat; | |
885 DCHECK_EQ(mfc_output_buffer_pixelformat_, V4L2_PIX_FMT_NV12MT_16X16); | |
886 DVLOG(3) << "New resolution: " << frame_buffer_size_.ToString(); | |
sheu
2013/08/09 09:23:16
I got in the habit of "CreateBuffersForFormat(): B
Pawel Osciak
2013/08/09 10:22:59
Done.
| |
887 | |
888 if (!CreateMfcOutputBuffers() || !CreateGscInputBuffers() || | |
889 !CreateGscOutputBuffers()) | |
890 return false; | |
891 | |
892 return true; | |
893 } | |
894 | |
839 bool ExynosVideoDecodeAccelerator::DecodeBufferInitial( | 895 bool ExynosVideoDecodeAccelerator::DecodeBufferInitial( |
840 const void* data, size_t size, size_t* endpos) { | 896 const void* data, size_t size, size_t* endpos) { |
841 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; | 897 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; |
842 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 898 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
843 DCHECK_NE(decoder_state_, kUninitialized); | 899 DCHECK_NE(decoder_state_, kUninitialized); |
844 DCHECK_NE(decoder_state_, kDecoding); | 900 DCHECK_NE(decoder_state_, kDecoding); |
845 DCHECK(!device_poll_thread_.IsRunning()); | 901 DCHECK(!device_poll_thread_.IsRunning()); |
846 // Initial decode. We haven't been able to get output stream format info yet. | 902 // Initial decode. We haven't been able to get output stream format info yet. |
847 // Get it, and start decoding. | 903 // Get it, and start decoding. |
848 | 904 |
849 // Copy in and send to HW. | 905 // Copy in and send to HW. |
850 if (!AppendToInputFrame(data, size)) | 906 if (!AppendToInputFrame(data, size)) |
851 return false; | 907 return false; |
852 | 908 |
853 // If we only have a partial frame, don't flush and process yet. | 909 // If we only have a partial frame, don't flush and process yet. |
854 if (decoder_partial_frame_pending_) | 910 if (decoder_partial_frame_pending_) |
855 return true; | 911 return true; |
856 | 912 |
857 if (!FlushInputFrame()) | 913 if (!FlushInputFrame()) |
858 return false; | 914 return false; |
859 | 915 |
860 // Recycle buffers. | 916 // Recycle buffers. |
861 DequeueMfc(); | 917 DequeueMfc(); |
862 | 918 |
863 // Check and see if we have format info yet. | 919 // Check and see if we have format info yet. |
864 struct v4l2_format format; | 920 struct v4l2_format format; |
865 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 921 bool again = false; |
866 if (ioctl(mfc_fd_, VIDIOC_G_FMT, &format) != 0) { | 922 if (!GetFormatInfo(&format, &again)) |
867 if (errno == EINVAL) { | 923 return false; |
868 // We will get EINVAL if we haven't seen sufficient stream to decode the | 924 |
869 // format. Return true and schedule the next buffer. | 925 if (again) { |
870 *endpos = size; | 926 // Need more stream to decode format, return true and schedule next buffer. |
871 return true; | 927 *endpos = size; |
872 } else { | 928 return true; |
873 DPLOG(ERROR) << "DecodeBufferInitial(): ioctl() failed: VIDIOC_G_FMT"; | |
874 NOTIFY_ERROR(PLATFORM_FAILURE); | |
875 return false; | |
876 } | |
877 } | 929 } |
878 | 930 |
879 // Run this initialization only on first startup. | 931 // Run this initialization only on first startup. |
880 if (decoder_state_ == kInitialized) { | 932 if (decoder_state_ == kInitialized) { |
881 DVLOG(3) << "DecodeBufferInitial(): running one-time initialization"; | 933 DVLOG(3) << "DecodeBufferInitial(): running one-time initialization"; |
sheu
2013/08/09 09:23:16
It's not one-time anymore.
Pawel Osciak
2013/08/09 10:22:59
Done.
| |
882 // Success! Setup our parameters. | 934 // Success! Setup our parameters. |
883 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); | 935 if (!CreateBuffersForFormat(format)) |
884 frame_buffer_size_.SetSize( | |
885 format.fmt.pix_mp.width, format.fmt.pix_mp.height); | |
886 mfc_output_buffer_size_[0] = format.fmt.pix_mp.plane_fmt[0].sizeimage; | |
887 mfc_output_buffer_size_[1] = format.fmt.pix_mp.plane_fmt[1].sizeimage; | |
888 mfc_output_buffer_pixelformat_ = format.fmt.pix_mp.pixelformat; | |
889 DCHECK_EQ(mfc_output_buffer_pixelformat_, V4L2_PIX_FMT_NV12MT_16X16); | |
890 | |
891 // Create our other buffers. | |
892 if (!CreateMfcOutputBuffers() || !CreateGscInputBuffers() || | |
893 !CreateGscOutputBuffers()) | |
894 return false; | 936 return false; |
895 | 937 |
896 // MFC expects to process the initial buffer once during stream init to | 938 // MFC expects to process the initial buffer once during stream init to |
897 // configure stream parameters, but will not consume the steam data on that | 939 // configure stream parameters, but will not consume the steam data on that |
898 // iteration. Subsequent iterations (including after reset) do not require | 940 // iteration. Subsequent iterations (including after reset) do not require |
899 // the stream init step. | 941 // the stream init step. |
900 *endpos = 0; | 942 *endpos = 0; |
901 } else { | 943 } else { |
902 *endpos = size; | 944 *endpos = size; |
903 } | 945 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 | 1099 |
1058 // Take ownership of the EGLImage and fd. | 1100 // Take ownership of the EGLImage and fd. |
1059 buffer.egl_image = EGL_NO_IMAGE_KHR; | 1101 buffer.egl_image = EGL_NO_IMAGE_KHR; |
1060 buffer.egl_image_fd = -1; | 1102 buffer.egl_image_fd = -1; |
1061 // And add this buffer to the free list. | 1103 // And add this buffer to the free list. |
1062 gsc_free_output_buffers_.push_back(i); | 1104 gsc_free_output_buffers_.push_back(i); |
1063 } | 1105 } |
1064 | 1106 |
1065 // We got buffers! Kick the GSC. | 1107 // We got buffers! Kick the GSC. |
1066 EnqueueGsc(); | 1108 EnqueueGsc(); |
1109 | |
1110 if (decoder_state_ == kChangingResolution) | |
1111 ResumeAfterResolutionChangeTask(); | |
1067 } | 1112 } |
1068 | 1113 |
1069 void ExynosVideoDecodeAccelerator::ServiceDeviceTask() { | 1114 void ExynosVideoDecodeAccelerator::ServiceDeviceTask(bool event_pending) { |
1070 DVLOG(3) << "ServiceDeviceTask()"; | 1115 DVLOG(3) << "ServiceDeviceTask()"; |
1071 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1116 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1072 DCHECK_NE(decoder_state_, kUninitialized); | 1117 DCHECK_NE(decoder_state_, kUninitialized); |
1073 DCHECK_NE(decoder_state_, kInitialized); | 1118 DCHECK_NE(decoder_state_, kInitialized); |
1074 DCHECK_NE(decoder_state_, kAfterReset); | 1119 DCHECK_NE(decoder_state_, kAfterReset); |
1075 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask"); | 1120 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask"); |
1076 | 1121 |
1077 if (decoder_state_ == kResetting) { | 1122 if (decoder_state_ == kResetting) { |
1078 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; | 1123 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; |
1079 return; | 1124 return; |
1080 } else if (decoder_state_ == kError) { | 1125 } else if (decoder_state_ == kError) { |
1081 DVLOG(2) << "ServiceDeviceTask(): early out: kError state"; | 1126 DVLOG(2) << "ServiceDeviceTask(): early out: kError state"; |
1082 return; | 1127 return; |
1128 } else if (decoder_state_ == kChangingResolution) { | |
1129 DVLOG(2) << "ServiceDeviceTask(): early out: kChangingResolution state"; | |
1130 return; | |
1083 } | 1131 } |
1084 | 1132 |
1133 if (event_pending) | |
1134 DequeueEvents(); | |
1085 DequeueMfc(); | 1135 DequeueMfc(); |
1086 DequeueGsc(); | 1136 DequeueGsc(); |
1087 EnqueueMfc(); | 1137 EnqueueMfc(); |
1088 EnqueueGsc(); | 1138 EnqueueGsc(); |
1089 | 1139 |
1090 // Clear the interrupt fd. | 1140 // Clear the interrupt fd. |
1091 if (!ClearDevicePollInterrupt()) | 1141 if (!ClearDevicePollInterrupt()) |
1092 return; | 1142 return; |
1093 | 1143 |
1094 unsigned int poll_fds = 0; | 1144 unsigned int poll_fds = 0; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 << mfc_output_gsc_input_queue_.size() << " => GSC[" | 1176 << mfc_output_gsc_input_queue_.size() << " => GSC[" |
1127 << gsc_free_input_buffers_.size() << "+" | 1177 << gsc_free_input_buffers_.size() << "+" |
1128 << gsc_input_buffer_queued_count_ << "/" | 1178 << gsc_input_buffer_queued_count_ << "/" |
1129 << gsc_input_buffer_map_.size() << "->" | 1179 << gsc_input_buffer_map_.size() << "->" |
1130 << gsc_free_output_buffers_.size() << "+" | 1180 << gsc_free_output_buffers_.size() << "+" |
1131 << gsc_output_buffer_queued_count_ << "/" | 1181 << gsc_output_buffer_queued_count_ << "/" |
1132 << gsc_output_buffer_map_.size() << "] => VDA[" | 1182 << gsc_output_buffer_map_.size() << "] => VDA[" |
1133 << decoder_frames_at_client_ << "]"; | 1183 << decoder_frames_at_client_ << "]"; |
1134 | 1184 |
1135 ScheduleDecodeBufferTaskIfNeeded(); | 1185 ScheduleDecodeBufferTaskIfNeeded(); |
1186 StartResolutionChangeIfNeeded(); | |
1187 } | |
1188 | |
1189 void ExynosVideoDecodeAccelerator::StartResolutionChangeIfNeeded() { | |
1190 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | |
1191 DCHECK_NE(decoder_state_, kUninitialized); | |
sheu
2013/08/09 09:23:16
DCHECK_EQ(decoder_state_, kDecoding)
Pawel Osciak
2013/08/09 10:22:59
Done.
| |
1192 | |
1193 if (!resolution_change_pending_) | |
1194 return; | |
1195 | |
1196 if (!mfc_output_gsc_input_queue_.empty() || | |
sheu
2013/08/09 09:23:16
Do we need to wait for mfc_output_buffer_queued_co
Pawel Osciak
2013/08/09 10:22:59
The event will happen after MFC internal queues ar
| |
1197 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ > 0) { | |
1198 DVLOG(3) << "StartResolutionChangeIfNeeded(): waiting for GSC to finish."; | |
1199 return; | |
1200 } | |
1201 | |
1202 DVLOG(3) << "No more work for GSC, initiate resolution change"; | |
1203 decoder_state_ = kChangingResolution; | |
1204 | |
1205 // Keep MFC input queue. | |
1206 if (!StopDevicePoll(true)) | |
1207 return; | |
1208 | |
1209 // Post a task to clean up buffers on child thread. This will also ensure | |
1210 // that we won't accept ReusePictureBuffer() anymore after that. | |
1211 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | |
1212 &ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers, | |
1213 weak_this_)); | |
1214 } | |
1215 | |
1216 void ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers() { | |
sheu
2013/08/09 09:23:16
We should run this on the decoder_thread_, since t
Pawel Osciak
2013/08/09 10:22:59
As per offline chat, we'll do this in a separate C
| |
1217 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); | |
1218 DVLOG(3) << "ResolutionChangeDestroyBuffers()"; | |
1219 | |
1220 DestroyGscInputBuffers(); | |
1221 DestroyGscOutputBuffers(); | |
1222 DestroyMfcOutputBuffers(); | |
1223 | |
1224 // Finish resolution change on decoder thread. | |
1225 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | |
1226 &ExynosVideoDecodeAccelerator::FinishResolutionChangeTask, | |
1227 base::Unretained(this))); | |
1228 } | |
1229 | |
1230 void ExynosVideoDecodeAccelerator::FinishResolutionChangeTask() { | |
1231 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | |
1232 DVLOG(3) << "FinishResolutionChangeTask()"; | |
1233 | |
1234 DCHECK(resolution_change_pending_); | |
1235 resolution_change_pending_ = false; | |
1236 | |
1237 struct v4l2_format format; | |
1238 bool again; | |
1239 bool ret = GetFormatInfo(&format, &again); | |
1240 if (!ret || again) { | |
1241 DVLOG(3) << "Couldn't get format information after resolution change"; | |
1242 return; | |
1243 } | |
1244 | |
1245 if (!CreateBuffersForFormat(format)) | |
1246 DVLOG(3) << "Couldn't reallocate buffers after resolution change"; | |
1247 | |
1248 // From here we stay in kChangingResolution and wait for | |
1249 // AssignPictureBuffers() before we can resume. | |
1250 } | |
1251 | |
1252 void ExynosVideoDecodeAccelerator::ResumeAfterResolutionChangeTask() { | |
1253 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | |
1254 DVLOG(3) << "ResumeAfterResolutionChangeTask()"; | |
1255 | |
1256 if (!StartDevicePoll()) | |
1257 return; | |
1258 | |
1259 decoder_state_ = kDecoding; | |
1260 EnqueueMfc(); | |
1261 // Gsc will get enqueued in AssignPictureBuffersTask(). | |
1262 ScheduleDecodeBufferTaskIfNeeded(); | |
1136 } | 1263 } |
1137 | 1264 |
1138 void ExynosVideoDecodeAccelerator::EnqueueMfc() { | 1265 void ExynosVideoDecodeAccelerator::EnqueueMfc() { |
1139 DVLOG(3) << "EnqueueMfc()"; | 1266 DVLOG(3) << "EnqueueMfc()"; |
1140 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1267 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1141 DCHECK_NE(decoder_state_, kUninitialized); | 1268 DCHECK_NE(decoder_state_, kUninitialized); |
1142 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueMfc"); | 1269 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueMfc"); |
1143 | 1270 |
1144 // Drain the pipe of completed decode buffers. | 1271 // Drain the pipe of completed decode buffers. |
1145 const int old_mfc_inputs_queued = mfc_input_buffer_queued_count_; | 1272 const int old_mfc_inputs_queued = mfc_input_buffer_queued_count_; |
(...skipping 27 matching lines...) Expand all Loading... | |
1173 return; | 1300 return; |
1174 // Start VIDIOC_STREAMON if we haven't yet. | 1301 // Start VIDIOC_STREAMON if we haven't yet. |
1175 if (!mfc_output_streamon_) { | 1302 if (!mfc_output_streamon_) { |
1176 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1303 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1177 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type); | 1304 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type); |
1178 mfc_output_streamon_ = true; | 1305 mfc_output_streamon_ = true; |
1179 } | 1306 } |
1180 } | 1307 } |
1181 } | 1308 } |
1182 | 1309 |
1310 void ExynosVideoDecodeAccelerator::DequeueEvents() { | |
1311 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | |
1312 DCHECK_NE(decoder_state_, kUninitialized); | |
sheu
2013/08/09 09:23:16
this really should just be DCHECK_EQ(decoder_state
Pawel Osciak
2013/08/09 10:22:59
Done.
| |
1313 DVLOG(3) << "DequeueEvents()"; | |
1314 | |
1315 struct v4l2_event ev; | |
1316 memset(&ev, 0, sizeof(ev)); | |
1317 | |
1318 while (ioctl(mfc_fd_, VIDIOC_DQEVENT, &ev) == 0) { | |
1319 if (ev.type == V4L2_EVENT_RESOLUTION_CHANGE) { | |
1320 DVLOG(3) << "DequeueEvents(): got resolution change event."; | |
1321 DCHECK(!resolution_change_pending_); | |
1322 resolution_change_pending_ = true; | |
1323 } | |
1324 } | |
1325 } | |
1326 | |
1183 void ExynosVideoDecodeAccelerator::DequeueMfc() { | 1327 void ExynosVideoDecodeAccelerator::DequeueMfc() { |
1184 DVLOG(3) << "DequeueMfc()"; | 1328 DVLOG(3) << "DequeueMfc()"; |
1185 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1329 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1186 DCHECK_NE(decoder_state_, kUninitialized); | 1330 DCHECK_NE(decoder_state_, kUninitialized); |
1187 TRACE_EVENT0("Video Decoder", "EVDA::DequeueMfc"); | 1331 TRACE_EVENT0("Video Decoder", "EVDA::DequeueMfc"); |
1188 | 1332 |
1189 // Dequeue completed MFC input (VIDEO_OUTPUT) buffers, and recycle to the free | 1333 // Dequeue completed MFC input (VIDEO_OUTPUT) buffers, and recycle to the free |
1190 // list. | 1334 // list. |
1191 struct v4l2_buffer dqbuf; | 1335 struct v4l2_buffer dqbuf; |
1192 struct v4l2_plane planes[2]; | 1336 struct v4l2_plane planes[2]; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 << picture_buffer_id; | 1675 << picture_buffer_id; |
1532 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1676 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1533 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask"); | 1677 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask"); |
1534 | 1678 |
1535 // We run ReusePictureBufferTask even if we're in kResetting. | 1679 // We run ReusePictureBufferTask even if we're in kResetting. |
1536 if (decoder_state_ == kError) { | 1680 if (decoder_state_ == kError) { |
1537 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; | 1681 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; |
1538 return; | 1682 return; |
1539 } | 1683 } |
1540 | 1684 |
1685 if (decoder_state_ == kChangingResolution) { | |
1686 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution"; | |
1687 return; | |
1688 } | |
1689 | |
1541 size_t index; | 1690 size_t index; |
1542 for (index = 0; index < gsc_output_buffer_map_.size(); ++index) | 1691 for (index = 0; index < gsc_output_buffer_map_.size(); ++index) |
1543 if (gsc_output_buffer_map_[index].picture_id == picture_buffer_id) | 1692 if (gsc_output_buffer_map_[index].picture_id == picture_buffer_id) |
1544 break; | 1693 break; |
1545 | 1694 |
1546 if (index >= gsc_output_buffer_map_.size()) { | 1695 if (index >= gsc_output_buffer_map_.size()) { |
1547 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found"; | 1696 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found"; |
1548 NOTIFY_ERROR(INVALID_ARGUMENT); | 1697 NOTIFY_ERROR(INVALID_ARGUMENT); |
1549 return; | 1698 return; |
1550 } | 1699 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1612 decoder_delay_bitstream_buffer_id_) | 1761 decoder_delay_bitstream_buffer_id_) |
1613 return; | 1762 return; |
1614 } | 1763 } |
1615 if (decoder_current_input_buffer_ != -1) | 1764 if (decoder_current_input_buffer_ != -1) |
1616 return; | 1765 return; |
1617 if ((mfc_input_ready_queue_.size() + | 1766 if ((mfc_input_ready_queue_.size() + |
1618 mfc_input_buffer_queued_count_ + mfc_output_gsc_input_queue_.size() + | 1767 mfc_input_buffer_queued_count_ + mfc_output_gsc_input_queue_.size() + |
1619 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ ) != 0) | 1768 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ ) != 0) |
1620 return; | 1769 return; |
1621 | 1770 |
1771 // TODO(posciak): crbug.com/270039. MFC requires a streamoff-streamon | |
1772 // sequence after flush to continue, even if we are not resetting. This would | |
1773 // make sense, because we don't really want to resume from a non-resume point | |
1774 // (e.g. not from an IDR) if we are flushed. | |
1775 // MSE player however triggers a Flush() on chunk end, but never Reset(). One | |
1776 // could argue either way, or even say that Flush() is not needed/harmful when | |
1777 // transitioning to next chunk. | |
1778 // For now, do the streamoff-streamon cycle to satisfy MFC and not freeze when | |
1779 // doing MSE. This should be harmless otherwise. | |
1780 if (!StopDevicePoll(false)) | |
1781 return; | |
1782 | |
1783 if (!StartDevicePoll()) | |
1784 return; | |
1785 | |
1622 decoder_delay_bitstream_buffer_id_ = -1; | 1786 decoder_delay_bitstream_buffer_id_ = -1; |
1623 decoder_flushing_ = false; | 1787 decoder_flushing_ = false; |
1624 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; | 1788 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; |
1625 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 1789 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1626 &Client::NotifyFlushDone, client_)); | 1790 &Client::NotifyFlushDone, client_)); |
1627 | 1791 |
1628 // While we were flushing, we early-outed DecodeBufferTask()s. | 1792 // While we were flushing, we early-outed DecodeBufferTask()s. |
1629 ScheduleDecodeBufferTaskIfNeeded(); | 1793 ScheduleDecodeBufferTaskIfNeeded(); |
1630 } | 1794 } |
1631 | 1795 |
1632 void ExynosVideoDecodeAccelerator::ResetTask() { | 1796 void ExynosVideoDecodeAccelerator::ResetTask() { |
sheu
2013/08/09 09:23:16
Drain the V4L2 event queue and reset resolution_ch
Pawel Osciak
2013/08/09 10:22:59
Done.
| |
1633 DVLOG(3) << "ResetTask()"; | 1797 DVLOG(3) << "ResetTask()"; |
1634 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1798 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1635 TRACE_EVENT0("Video Decoder", "EVDA::ResetTask"); | 1799 TRACE_EVENT0("Video Decoder", "EVDA::ResetTask"); |
1636 | 1800 |
1637 if (decoder_state_ == kError) { | 1801 if (decoder_state_ == kError) { |
1638 DVLOG(2) << "ResetTask(): early out: kError state"; | 1802 DVLOG(2) << "ResetTask(): early out: kError state"; |
1639 return; | 1803 return; |
1640 } | 1804 } |
1641 | 1805 |
1642 // We stop streaming, but we _don't_ destroy our buffers. | 1806 // We stop streaming, but we _don't_ destroy our buffers. |
1643 if (!StopDevicePoll()) | 1807 if (!StopDevicePoll(false)) |
1644 return; | 1808 return; |
1645 | 1809 |
1646 decoder_current_bitstream_buffer_.reset(); | 1810 decoder_current_bitstream_buffer_.reset(); |
1647 decoder_input_queue_.clear(); | 1811 decoder_input_queue_.clear(); |
1648 | 1812 |
1649 decoder_current_input_buffer_ = -1; | 1813 decoder_current_input_buffer_ = -1; |
1650 | 1814 |
1651 // If we were flushing, we'll never return any more BitstreamBuffers or | 1815 // If we were flushing, we'll never return any more BitstreamBuffers or |
1652 // PictureBuffers; they have all been dropped and returned by now. | 1816 // PictureBuffers; they have all been dropped and returned by now. |
1653 NotifyFlushDoneIfNeeded(); | 1817 NotifyFlushDoneIfNeeded(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1687 ScheduleDecodeBufferTaskIfNeeded(); | 1851 ScheduleDecodeBufferTaskIfNeeded(); |
1688 } | 1852 } |
1689 | 1853 |
1690 void ExynosVideoDecodeAccelerator::DestroyTask() { | 1854 void ExynosVideoDecodeAccelerator::DestroyTask() { |
1691 DVLOG(3) << "DestroyTask()"; | 1855 DVLOG(3) << "DestroyTask()"; |
1692 TRACE_EVENT0("Video Decoder", "EVDA::DestroyTask"); | 1856 TRACE_EVENT0("Video Decoder", "EVDA::DestroyTask"); |
1693 | 1857 |
1694 // DestroyTask() should run regardless of decoder_state_. | 1858 // DestroyTask() should run regardless of decoder_state_. |
1695 | 1859 |
1696 // Stop streaming and the device_poll_thread_. | 1860 // Stop streaming and the device_poll_thread_. |
1697 StopDevicePoll(); | 1861 StopDevicePoll(false); |
1698 | 1862 |
1699 decoder_current_bitstream_buffer_.reset(); | 1863 decoder_current_bitstream_buffer_.reset(); |
1700 decoder_current_input_buffer_ = -1; | 1864 decoder_current_input_buffer_ = -1; |
1701 decoder_decode_buffer_tasks_scheduled_ = 0; | 1865 decoder_decode_buffer_tasks_scheduled_ = 0; |
1702 decoder_frames_at_client_ = 0; | 1866 decoder_frames_at_client_ = 0; |
1703 decoder_input_queue_.clear(); | 1867 decoder_input_queue_.clear(); |
1704 decoder_flushing_ = false; | 1868 decoder_flushing_ = false; |
1705 | 1869 |
1706 // Set our state to kError. Just in case. | 1870 // Set our state to kError. Just in case. |
1707 decoder_state_ = kError; | 1871 decoder_state_ = kError; |
(...skipping 11 matching lines...) Expand all Loading... | |
1719 return false; | 1883 return false; |
1720 } | 1884 } |
1721 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 1885 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1722 &ExynosVideoDecodeAccelerator::DevicePollTask, | 1886 &ExynosVideoDecodeAccelerator::DevicePollTask, |
1723 base::Unretained(this), | 1887 base::Unretained(this), |
1724 0)); | 1888 0)); |
1725 | 1889 |
1726 return true; | 1890 return true; |
1727 } | 1891 } |
1728 | 1892 |
1729 bool ExynosVideoDecodeAccelerator::StopDevicePoll() { | 1893 bool ExynosVideoDecodeAccelerator::StopDevicePoll(bool keep_mfc_input) { |
1730 DVLOG(3) << "StopDevicePoll()"; | 1894 DVLOG(3) << "StopDevicePoll()"; |
1731 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 1895 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
1732 | 1896 |
1733 // Signal the DevicePollTask() to stop, and stop the device poll thread. | 1897 // Signal the DevicePollTask() to stop, and stop the device poll thread. |
1734 if (!SetDevicePollInterrupt()) | 1898 if (!SetDevicePollInterrupt()) |
1735 return false; | 1899 return false; |
1736 device_poll_thread_.Stop(); | 1900 device_poll_thread_.Stop(); |
1737 // Clear the interrupt now, to be sure. | 1901 // Clear the interrupt now, to be sure. |
1738 if (!ClearDevicePollInterrupt()) | 1902 if (!ClearDevicePollInterrupt()) |
1739 return false; | 1903 return false; |
1740 | 1904 |
1741 // Stop streaming. | 1905 // Stop streaming. |
1742 if (mfc_input_streamon_) { | 1906 if (!keep_mfc_input) { |
1743 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1907 if (mfc_input_streamon_) { |
1744 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); | 1908 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1909 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); | |
1910 } | |
1911 mfc_input_streamon_ = false; | |
1745 } | 1912 } |
1746 mfc_input_streamon_ = false; | |
1747 if (mfc_output_streamon_) { | 1913 if (mfc_output_streamon_) { |
1748 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1914 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1749 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); | 1915 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); |
1750 } | 1916 } |
1751 mfc_output_streamon_ = false; | 1917 mfc_output_streamon_ = false; |
1752 if (gsc_input_streamon_) { | 1918 if (gsc_input_streamon_) { |
1753 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1919 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
1754 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type); | 1920 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type); |
1755 } | 1921 } |
1756 gsc_input_streamon_ = false; | 1922 gsc_input_streamon_ = false; |
1757 if (gsc_output_streamon_) { | 1923 if (gsc_output_streamon_) { |
1758 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 1924 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
1759 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type); | 1925 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type); |
1760 } | 1926 } |
1761 gsc_output_streamon_ = false; | 1927 gsc_output_streamon_ = false; |
1762 | 1928 |
1763 // Reset all our accounting info. | 1929 // Reset all our accounting info. |
1764 mfc_input_ready_queue_.clear(); | 1930 if (!keep_mfc_input) { |
1765 mfc_free_input_buffers_.clear(); | 1931 mfc_input_ready_queue_.clear(); |
1766 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { | 1932 mfc_free_input_buffers_.clear(); |
1767 mfc_free_input_buffers_.push_back(i); | 1933 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { |
1768 mfc_input_buffer_map_[i].at_device = false; | 1934 mfc_free_input_buffers_.push_back(i); |
1769 mfc_input_buffer_map_[i].bytes_used = 0; | 1935 mfc_input_buffer_map_[i].at_device = false; |
1770 mfc_input_buffer_map_[i].input_id = -1; | 1936 mfc_input_buffer_map_[i].bytes_used = 0; |
1937 mfc_input_buffer_map_[i].input_id = -1; | |
1938 } | |
1939 mfc_input_buffer_queued_count_ = 0; | |
1771 } | 1940 } |
1772 mfc_input_buffer_queued_count_ = 0; | |
1773 mfc_free_output_buffers_.clear(); | 1941 mfc_free_output_buffers_.clear(); |
1774 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { | 1942 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { |
1775 mfc_free_output_buffers_.push_back(i); | 1943 mfc_free_output_buffers_.push_back(i); |
1776 mfc_output_buffer_map_[i].at_device = false; | 1944 mfc_output_buffer_map_[i].at_device = false; |
1777 mfc_output_buffer_map_[i].input_id = -1; | 1945 mfc_output_buffer_map_[i].input_id = -1; |
1778 } | 1946 } |
1779 mfc_output_buffer_queued_count_ = 0; | 1947 mfc_output_buffer_queued_count_ = 0; |
1780 mfc_output_gsc_input_queue_.clear(); | 1948 mfc_output_gsc_input_queue_.clear(); |
1781 gsc_free_input_buffers_.clear(); | 1949 gsc_free_input_buffers_.clear(); |
1782 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) { | 1950 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1834 DVLOG(3) << "DevicePollTask()"; | 2002 DVLOG(3) << "DevicePollTask()"; |
1835 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); | 2003 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); |
1836 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask"); | 2004 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask"); |
1837 | 2005 |
1838 // This routine just polls the set of device fds, and schedules a | 2006 // This routine just polls the set of device fds, and schedules a |
1839 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. | 2007 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. |
1840 // Other threads may notify this task to return early by writing to | 2008 // Other threads may notify this task to return early by writing to |
1841 // device_poll_interrupt_fd_. | 2009 // device_poll_interrupt_fd_. |
1842 struct pollfd pollfds[3]; | 2010 struct pollfd pollfds[3]; |
1843 nfds_t nfds; | 2011 nfds_t nfds; |
2012 int mfc_pollfd = -1; | |
1844 | 2013 |
1845 // Add device_poll_interrupt_fd_; | 2014 // Add device_poll_interrupt_fd_; |
1846 pollfds[0].fd = device_poll_interrupt_fd_; | 2015 pollfds[0].fd = device_poll_interrupt_fd_; |
1847 pollfds[0].events = POLLIN | POLLERR; | 2016 pollfds[0].events = POLLIN | POLLERR; |
1848 nfds = 1; | 2017 nfds = 1; |
1849 | 2018 |
1850 if (poll_fds & kPollMfc) { | 2019 if (poll_fds & kPollMfc) { |
1851 DVLOG(3) << "DevicePollTask(): adding MFC to poll() set"; | 2020 DVLOG(3) << "DevicePollTask(): adding MFC to poll() set"; |
1852 pollfds[nfds].fd = mfc_fd_; | 2021 pollfds[nfds].fd = mfc_fd_; |
1853 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR; | 2022 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR | POLLPRI; |
2023 mfc_pollfd = nfds; | |
1854 nfds++; | 2024 nfds++; |
1855 } | 2025 } |
1856 // Add GSC fd, if we should poll on it. | 2026 // Add GSC fd, if we should poll on it. |
1857 // GSC has to wait until both input and output buffers are queued. | 2027 // GSC has to wait until both input and output buffers are queued. |
1858 if (poll_fds & kPollGsc) { | 2028 if (poll_fds & kPollGsc) { |
1859 DVLOG(3) << "DevicePollTask(): adding GSC to poll() set"; | 2029 DVLOG(3) << "DevicePollTask(): adding GSC to poll() set"; |
1860 pollfds[nfds].fd = gsc_fd_; | 2030 pollfds[nfds].fd = gsc_fd_; |
1861 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR; | 2031 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR; |
1862 nfds++; | 2032 nfds++; |
1863 } | 2033 } |
1864 | 2034 |
1865 // Poll it! | 2035 // Poll it! |
1866 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { | 2036 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { |
1867 DPLOG(ERROR) << "DevicePollTask(): poll() failed"; | 2037 DPLOG(ERROR) << "DevicePollTask(): poll() failed"; |
1868 NOTIFY_ERROR(PLATFORM_FAILURE); | 2038 NOTIFY_ERROR(PLATFORM_FAILURE); |
1869 return; | 2039 return; |
1870 } | 2040 } |
1871 | 2041 |
2042 bool event_pending = (mfc_pollfd != -1 && | |
2043 pollfds[mfc_pollfd].revents & POLLPRI); | |
2044 | |
1872 // All processing should happen on ServiceDeviceTask(), since we shouldn't | 2045 // All processing should happen on ServiceDeviceTask(), since we shouldn't |
1873 // touch decoder state from this thread. | 2046 // touch decoder state from this thread. |
1874 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( | 2047 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( |
1875 &ExynosVideoDecodeAccelerator::ServiceDeviceTask, | 2048 &ExynosVideoDecodeAccelerator::ServiceDeviceTask, |
1876 base::Unretained(this))); | 2049 base::Unretained(this), event_pending)); |
1877 } | 2050 } |
1878 | 2051 |
1879 void ExynosVideoDecodeAccelerator::NotifyError(Error error) { | 2052 void ExynosVideoDecodeAccelerator::NotifyError(Error error) { |
1880 DVLOG(2) << "NotifyError()"; | 2053 DVLOG(2) << "NotifyError()"; |
1881 | 2054 |
1882 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { | 2055 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { |
1883 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 2056 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
1884 &ExynosVideoDecodeAccelerator::NotifyError, weak_this_, error)); | 2057 &ExynosVideoDecodeAccelerator::NotifyError, weak_this_, error)); |
1885 return; | 2058 return; |
1886 } | 2059 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1962 } | 2135 } |
1963 mfc_input_buffer_map_[i].address = address; | 2136 mfc_input_buffer_map_[i].address = address; |
1964 mfc_input_buffer_map_[i].length = buffer.m.planes[0].length; | 2137 mfc_input_buffer_map_[i].length = buffer.m.planes[0].length; |
1965 } | 2138 } |
1966 | 2139 |
1967 return true; | 2140 return true; |
1968 } | 2141 } |
1969 | 2142 |
1970 bool ExynosVideoDecodeAccelerator::CreateMfcOutputBuffers() { | 2143 bool ExynosVideoDecodeAccelerator::CreateMfcOutputBuffers() { |
1971 DVLOG(3) << "CreateMfcOutputBuffers()"; | 2144 DVLOG(3) << "CreateMfcOutputBuffers()"; |
1972 DCHECK_EQ(decoder_state_, kInitialized); | 2145 DCHECK(decoder_state_ == kInitialized || |
2146 decoder_state_ == kChangingResolution); | |
1973 DCHECK(!mfc_output_streamon_); | 2147 DCHECK(!mfc_output_streamon_); |
1974 DCHECK(mfc_output_buffer_map_.empty()); | 2148 DCHECK(mfc_output_buffer_map_.empty()); |
1975 | 2149 |
1976 // Number of MFC output buffers we need. | 2150 // Number of MFC output buffers we need. |
1977 struct v4l2_control ctrl; | 2151 struct v4l2_control ctrl; |
1978 memset(&ctrl, 0, sizeof(ctrl)); | 2152 memset(&ctrl, 0, sizeof(ctrl)); |
1979 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; | 2153 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; |
1980 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_G_CTRL, &ctrl); | 2154 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_G_CTRL, &ctrl); |
1981 mfc_output_dpb_size_ = ctrl.value; | 2155 mfc_output_dpb_size_ = ctrl.value; |
1982 | 2156 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2019 mfc_output_buffer_map_[i].address[j] = address; | 2193 mfc_output_buffer_map_[i].address[j] = address; |
2020 mfc_output_buffer_map_[i].length[j] = buffer.m.planes[j].length; | 2194 mfc_output_buffer_map_[i].length[j] = buffer.m.planes[j].length; |
2021 } | 2195 } |
2022 } | 2196 } |
2023 | 2197 |
2024 return true; | 2198 return true; |
2025 } | 2199 } |
2026 | 2200 |
2027 bool ExynosVideoDecodeAccelerator::CreateGscInputBuffers() { | 2201 bool ExynosVideoDecodeAccelerator::CreateGscInputBuffers() { |
2028 DVLOG(3) << "CreateGscInputBuffers()"; | 2202 DVLOG(3) << "CreateGscInputBuffers()"; |
2029 DCHECK_EQ(decoder_state_, kInitialized); | 2203 DCHECK(decoder_state_ == kInitialized || |
2204 decoder_state_ == kChangingResolution); | |
2030 DCHECK(!gsc_input_streamon_); | 2205 DCHECK(!gsc_input_streamon_); |
2031 DCHECK(gsc_input_buffer_map_.empty()); | 2206 DCHECK(gsc_input_buffer_map_.empty()); |
2032 | 2207 |
2033 struct v4l2_format format; | 2208 struct v4l2_format format; |
2034 memset(&format, 0, sizeof(format)); | 2209 memset(&format, 0, sizeof(format)); |
2035 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 2210 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
2036 format.fmt.pix_mp.width = frame_buffer_size_.width(); | 2211 format.fmt.pix_mp.width = frame_buffer_size_.width(); |
2037 format.fmt.pix_mp.height = frame_buffer_size_.height(); | 2212 format.fmt.pix_mp.height = frame_buffer_size_.height(); |
2038 format.fmt.pix_mp.pixelformat = mfc_output_buffer_pixelformat_; | 2213 format.fmt.pix_mp.pixelformat = mfc_output_buffer_pixelformat_; |
2039 format.fmt.pix_mp.plane_fmt[0].sizeimage = mfc_output_buffer_size_[0]; | 2214 format.fmt.pix_mp.plane_fmt[0].sizeimage = mfc_output_buffer_size_[0]; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2082 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) { | 2257 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) { |
2083 gsc_free_input_buffers_.push_back(i); | 2258 gsc_free_input_buffers_.push_back(i); |
2084 gsc_input_buffer_map_[i].mfc_output = -1; | 2259 gsc_input_buffer_map_[i].mfc_output = -1; |
2085 } | 2260 } |
2086 | 2261 |
2087 return true; | 2262 return true; |
2088 } | 2263 } |
2089 | 2264 |
2090 bool ExynosVideoDecodeAccelerator::CreateGscOutputBuffers() { | 2265 bool ExynosVideoDecodeAccelerator::CreateGscOutputBuffers() { |
2091 DVLOG(3) << "CreateGscOutputBuffers()"; | 2266 DVLOG(3) << "CreateGscOutputBuffers()"; |
2092 DCHECK_EQ(decoder_state_, kInitialized); | 2267 DCHECK(decoder_state_ == kInitialized || |
2268 decoder_state_ == kChangingResolution); | |
2093 DCHECK(!gsc_output_streamon_); | 2269 DCHECK(!gsc_output_streamon_); |
2094 DCHECK(gsc_output_buffer_map_.empty()); | 2270 DCHECK(gsc_output_buffer_map_.empty()); |
2095 | 2271 |
2096 // GSC outputs into the EGLImages we create from the textures we are | 2272 // GSC outputs into the EGLImages we create from the textures we are |
2097 // assigned. Assume RGBA8888 format. | 2273 // assigned. Assume RGBA8888 format. |
2098 struct v4l2_format format; | 2274 struct v4l2_format format; |
2099 memset(&format, 0, sizeof(format)); | 2275 memset(&format, 0, sizeof(format)); |
2100 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 2276 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
2101 format.fmt.pix_mp.width = frame_buffer_size_.width(); | 2277 format.fmt.pix_mp.width = frame_buffer_size_.width(); |
2102 format.fmt.pix_mp.height = frame_buffer_size_.height(); | 2278 format.fmt.pix_mp.height = frame_buffer_size_.height(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2209 | 2385 |
2210 size_t i = 0; | 2386 size_t i = 0; |
2211 do { | 2387 do { |
2212 GscOutputRecord& output_record = gsc_output_buffer_map_[i]; | 2388 GscOutputRecord& output_record = gsc_output_buffer_map_[i]; |
2213 if (output_record.fd != -1) | 2389 if (output_record.fd != -1) |
2214 HANDLE_EINTR(close(output_record.fd)); | 2390 HANDLE_EINTR(close(output_record.fd)); |
2215 if (output_record.egl_image != EGL_NO_IMAGE_KHR) | 2391 if (output_record.egl_image != EGL_NO_IMAGE_KHR) |
2216 eglDestroyImageKHR(egl_display_, output_record.egl_image); | 2392 eglDestroyImageKHR(egl_display_, output_record.egl_image); |
2217 if (output_record.egl_sync != EGL_NO_SYNC_KHR) | 2393 if (output_record.egl_sync != EGL_NO_SYNC_KHR) |
2218 eglDestroySyncKHR(egl_display_, output_record.egl_sync); | 2394 eglDestroySyncKHR(egl_display_, output_record.egl_sync); |
2219 if (client_) | 2395 if (client_) { |
2396 DVLOG(1) << "Dismissing PictureBuffer id=" << output_record.picture_id; | |
sheu
2013/08/09 09:23:16
(same as above) "DestroyGscOutputBuffers(): XXX "
Pawel Osciak
2013/08/09 10:22:59
Done.
| |
2220 client_->DismissPictureBuffer(output_record.picture_id); | 2397 client_->DismissPictureBuffer(output_record.picture_id); |
2398 } | |
2221 ++i; | 2399 ++i; |
2222 } while (i < gsc_output_buffer_map_.size()); | 2400 } while (i < gsc_output_buffer_map_.size()); |
2223 } | 2401 } |
2224 | 2402 |
2225 struct v4l2_requestbuffers reqbufs; | 2403 struct v4l2_requestbuffers reqbufs; |
2226 memset(&reqbufs, 0, sizeof(reqbufs)); | 2404 memset(&reqbufs, 0, sizeof(reqbufs)); |
2227 reqbufs.count = 0; | 2405 reqbufs.count = 0; |
2228 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 2406 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
2229 reqbufs.memory = V4L2_MEMORY_DMABUF; | 2407 reqbufs.memory = V4L2_MEMORY_DMABUF; |
2230 if (ioctl(gsc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) | 2408 if (ioctl(gsc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) |
2231 DPLOG(ERROR) << "DestroyGscOutputBuffers(): ioctl() failed: VIDIOC_REQBUFS"; | 2409 DPLOG(ERROR) << "DestroyGscOutputBuffers(): ioctl() failed: VIDIOC_REQBUFS"; |
2232 | 2410 |
2233 gsc_output_buffer_map_.clear(); | 2411 gsc_output_buffer_map_.clear(); |
2234 gsc_free_output_buffers_.clear(); | 2412 gsc_free_output_buffers_.clear(); |
2235 } | 2413 } |
2236 | 2414 |
2237 } // namespace content | 2415 } // namespace content |
OLD | NEW |