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

Side by Side Diff: content/common/gpu/media/exynos_video_decode_accelerator.cc

Issue 22590009: EVDA: Add support for dynamic resolution change and MSE players. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 4 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 (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
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
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
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
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
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 (HANDLE_EINTR(ioctl(mfc_fd_, VIDIOC_G_FMT, format)) != 0) {
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) << "CreateBuffersForFormat(): new resolution: "
887 << frame_buffer_size_.ToString();
888
889 if (!CreateMfcOutputBuffers() || !CreateGscInputBuffers() ||
890 !CreateGscOutputBuffers())
891 return false;
892
893 return true;
894 }
895
839 bool ExynosVideoDecodeAccelerator::DecodeBufferInitial( 896 bool ExynosVideoDecodeAccelerator::DecodeBufferInitial(
840 const void* data, size_t size, size_t* endpos) { 897 const void* data, size_t size, size_t* endpos) {
841 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size; 898 DVLOG(3) << "DecodeBufferInitial(): data=" << data << ", size=" << size;
842 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 899 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
843 DCHECK_NE(decoder_state_, kUninitialized); 900 DCHECK_NE(decoder_state_, kUninitialized);
844 DCHECK_NE(decoder_state_, kDecoding); 901 DCHECK_NE(decoder_state_, kDecoding);
845 DCHECK(!device_poll_thread_.IsRunning()); 902 DCHECK(!device_poll_thread_.IsRunning());
846 // Initial decode. We haven't been able to get output stream format info yet. 903 // Initial decode. We haven't been able to get output stream format info yet.
847 // Get it, and start decoding. 904 // Get it, and start decoding.
848 905
849 // Copy in and send to HW. 906 // Copy in and send to HW.
850 if (!AppendToInputFrame(data, size)) 907 if (!AppendToInputFrame(data, size))
851 return false; 908 return false;
852 909
853 // If we only have a partial frame, don't flush and process yet. 910 // If we only have a partial frame, don't flush and process yet.
854 if (decoder_partial_frame_pending_) 911 if (decoder_partial_frame_pending_)
855 return true; 912 return true;
856 913
857 if (!FlushInputFrame()) 914 if (!FlushInputFrame())
858 return false; 915 return false;
859 916
860 // Recycle buffers. 917 // Recycle buffers.
861 DequeueMfc(); 918 DequeueMfc();
862 919
863 // Check and see if we have format info yet. 920 // Check and see if we have format info yet.
864 struct v4l2_format format; 921 struct v4l2_format format;
865 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 922 bool again = false;
866 if (ioctl(mfc_fd_, VIDIOC_G_FMT, &format) != 0) { 923 if (!GetFormatInfo(&format, &again))
867 if (errno == EINVAL) { 924 return false;
868 // We will get EINVAL if we haven't seen sufficient stream to decode the 925
869 // format. Return true and schedule the next buffer. 926 if (again) {
870 *endpos = size; 927 // Need more stream to decode format, return true and schedule next buffer.
871 return true; 928 *endpos = size;
872 } else { 929 return true;
873 DPLOG(ERROR) << "DecodeBufferInitial(): ioctl() failed: VIDIOC_G_FMT";
874 NOTIFY_ERROR(PLATFORM_FAILURE);
875 return false;
876 }
877 } 930 }
878 931
879 // Run this initialization only on first startup. 932 // Run this initialization only on first startup.
880 if (decoder_state_ == kInitialized) { 933 if (decoder_state_ == kInitialized) {
881 DVLOG(3) << "DecodeBufferInitial(): running one-time initialization"; 934 DVLOG(3) << "DecodeBufferInitial(): running initialization";
882 // Success! Setup our parameters. 935 // Success! Setup our parameters.
883 CHECK_EQ(format.fmt.pix_mp.num_planes, 2); 936 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; 937 return false;
895 938
896 // MFC expects to process the initial buffer once during stream init to 939 // 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 940 // configure stream parameters, but will not consume the steam data on that
898 // iteration. Subsequent iterations (including after reset) do not require 941 // iteration. Subsequent iterations (including after reset) do not require
899 // the stream init step. 942 // the stream init step.
900 *endpos = 0; 943 *endpos = 0;
901 } else { 944 } else {
902 *endpos = size; 945 *endpos = size;
903 } 946 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 1100
1058 // Take ownership of the EGLImage and fd. 1101 // Take ownership of the EGLImage and fd.
1059 buffer.egl_image = EGL_NO_IMAGE_KHR; 1102 buffer.egl_image = EGL_NO_IMAGE_KHR;
1060 buffer.egl_image_fd = -1; 1103 buffer.egl_image_fd = -1;
1061 // And add this buffer to the free list. 1104 // And add this buffer to the free list.
1062 gsc_free_output_buffers_.push_back(i); 1105 gsc_free_output_buffers_.push_back(i);
1063 } 1106 }
1064 1107
1065 // We got buffers! Kick the GSC. 1108 // We got buffers! Kick the GSC.
1066 EnqueueGsc(); 1109 EnqueueGsc();
1110
1111 if (decoder_state_ == kChangingResolution)
1112 ResumeAfterResolutionChangeTask();
1067 } 1113 }
1068 1114
1069 void ExynosVideoDecodeAccelerator::ServiceDeviceTask() { 1115 void ExynosVideoDecodeAccelerator::ServiceDeviceTask(bool event_pending) {
1070 DVLOG(3) << "ServiceDeviceTask()"; 1116 DVLOG(3) << "ServiceDeviceTask()";
1071 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1117 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1072 DCHECK_NE(decoder_state_, kUninitialized); 1118 DCHECK_NE(decoder_state_, kUninitialized);
1073 DCHECK_NE(decoder_state_, kInitialized); 1119 DCHECK_NE(decoder_state_, kInitialized);
1074 DCHECK_NE(decoder_state_, kAfterReset); 1120 DCHECK_NE(decoder_state_, kAfterReset);
1075 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask"); 1121 TRACE_EVENT0("Video Decoder", "EVDA::ServiceDeviceTask");
1076 1122
1077 if (decoder_state_ == kResetting) { 1123 if (decoder_state_ == kResetting) {
1078 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state"; 1124 DVLOG(2) << "ServiceDeviceTask(): early out: kResetting state";
1079 return; 1125 return;
1080 } else if (decoder_state_ == kError) { 1126 } else if (decoder_state_ == kError) {
1081 DVLOG(2) << "ServiceDeviceTask(): early out: kError state"; 1127 DVLOG(2) << "ServiceDeviceTask(): early out: kError state";
1082 return; 1128 return;
1129 } else if (decoder_state_ == kChangingResolution) {
1130 DVLOG(2) << "ServiceDeviceTask(): early out: kChangingResolution state";
1131 return;
1083 } 1132 }
1084 1133
1134 if (event_pending)
1135 DequeueEvents();
1085 DequeueMfc(); 1136 DequeueMfc();
1086 DequeueGsc(); 1137 DequeueGsc();
1087 EnqueueMfc(); 1138 EnqueueMfc();
1088 EnqueueGsc(); 1139 EnqueueGsc();
1089 1140
1090 // Clear the interrupt fd. 1141 // Clear the interrupt fd.
1091 if (!ClearDevicePollInterrupt()) 1142 if (!ClearDevicePollInterrupt())
1092 return; 1143 return;
1093 1144
1094 unsigned int poll_fds = 0; 1145 unsigned int poll_fds = 0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 << mfc_output_gsc_input_queue_.size() << " => GSC[" 1177 << mfc_output_gsc_input_queue_.size() << " => GSC["
1127 << gsc_free_input_buffers_.size() << "+" 1178 << gsc_free_input_buffers_.size() << "+"
1128 << gsc_input_buffer_queued_count_ << "/" 1179 << gsc_input_buffer_queued_count_ << "/"
1129 << gsc_input_buffer_map_.size() << "->" 1180 << gsc_input_buffer_map_.size() << "->"
1130 << gsc_free_output_buffers_.size() << "+" 1181 << gsc_free_output_buffers_.size() << "+"
1131 << gsc_output_buffer_queued_count_ << "/" 1182 << gsc_output_buffer_queued_count_ << "/"
1132 << gsc_output_buffer_map_.size() << "] => VDA[" 1183 << gsc_output_buffer_map_.size() << "] => VDA["
1133 << decoder_frames_at_client_ << "]"; 1184 << decoder_frames_at_client_ << "]";
1134 1185
1135 ScheduleDecodeBufferTaskIfNeeded(); 1186 ScheduleDecodeBufferTaskIfNeeded();
1187 StartResolutionChangeIfNeeded();
1188 }
1189
1190 void ExynosVideoDecodeAccelerator::StartResolutionChangeIfNeeded() {
1191 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1192 DCHECK_EQ(decoder_state_, kDecoding);
1193
1194 if (!resolution_change_pending_)
1195 return;
1196
1197 if (!mfc_output_gsc_input_queue_.empty() ||
1198 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ > 0) {
1199 // MFC output is drained immediately after event is received, so it has
1200 // to be empty already before we get here.
1201 DCHECK_EQ(mfc_output_buffer_queued_count_, 0);
1202 DVLOG(3) << "StartResolutionChangeIfNeeded(): waiting for GSC to finish.";
1203 return;
1204 }
1205
1206 DVLOG(3) << "No more work for GSC, initiate resolution change";
1207
1208 // Keep MFC input queue.
1209 if (!StopDevicePoll(true))
1210 return;
1211
1212 decoder_state_ = kChangingResolution;
1213 DCHECK(resolution_change_pending_);
1214 resolution_change_pending_ = false;
1215
1216 // Post a task to clean up buffers on child thread. This will also ensure
1217 // that we won't accept ReusePictureBuffer() anymore after that.
1218 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
1219 &ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers,
1220 weak_this_));
1221 }
1222
1223 void ExynosVideoDecodeAccelerator::ResolutionChangeDestroyBuffers() {
1224 DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
1225 DVLOG(3) << "ResolutionChangeDestroyBuffers()";
1226
1227 DestroyGscInputBuffers();
1228 DestroyGscOutputBuffers();
1229 DestroyMfcOutputBuffers();
1230
1231 // Finish resolution change on decoder thread.
1232 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
1233 &ExynosVideoDecodeAccelerator::FinishResolutionChangeTask,
1234 base::Unretained(this)));
1235 }
1236
1237 void ExynosVideoDecodeAccelerator::FinishResolutionChangeTask() {
1238 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1239 DVLOG(3) << "FinishResolutionChangeTask()";
1240
1241 struct v4l2_format format;
1242 bool again;
1243 bool ret = GetFormatInfo(&format, &again);
1244 if (!ret || again) {
1245 DVLOG(3) << "Couldn't get format information after resolution change";
1246 return;
1247 }
1248
1249 if (!CreateBuffersForFormat(format))
1250 DVLOG(3) << "Couldn't reallocate buffers after resolution change";
1251
1252 // From here we stay in kChangingResolution and wait for
1253 // AssignPictureBuffers() before we can resume.
1254 }
1255
1256 void ExynosVideoDecodeAccelerator::ResumeAfterResolutionChangeTask() {
1257 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1258 DVLOG(3) << "ResumeAfterResolutionChangeTask()";
1259
1260 if (!StartDevicePoll())
1261 return;
1262
1263 decoder_state_ = kDecoding;
1264 EnqueueMfc();
1265 // Gsc will get enqueued in AssignPictureBuffersTask().
1266 ScheduleDecodeBufferTaskIfNeeded();
1136 } 1267 }
1137 1268
1138 void ExynosVideoDecodeAccelerator::EnqueueMfc() { 1269 void ExynosVideoDecodeAccelerator::EnqueueMfc() {
1139 DVLOG(3) << "EnqueueMfc()"; 1270 DVLOG(3) << "EnqueueMfc()";
1140 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1271 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1141 DCHECK_NE(decoder_state_, kUninitialized); 1272 DCHECK_NE(decoder_state_, kUninitialized);
1142 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueMfc"); 1273 TRACE_EVENT0("Video Decoder", "EVDA::EnqueueMfc");
1143 1274
1144 // Drain the pipe of completed decode buffers. 1275 // Drain the pipe of completed decode buffers.
1145 const int old_mfc_inputs_queued = mfc_input_buffer_queued_count_; 1276 const int old_mfc_inputs_queued = mfc_input_buffer_queued_count_;
(...skipping 27 matching lines...) Expand all
1173 return; 1304 return;
1174 // Start VIDIOC_STREAMON if we haven't yet. 1305 // Start VIDIOC_STREAMON if we haven't yet.
1175 if (!mfc_output_streamon_) { 1306 if (!mfc_output_streamon_) {
1176 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1307 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1177 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type); 1308 IOCTL_OR_ERROR_RETURN(mfc_fd_, VIDIOC_STREAMON, &type);
1178 mfc_output_streamon_ = true; 1309 mfc_output_streamon_ = true;
1179 } 1310 }
1180 } 1311 }
1181 } 1312 }
1182 1313
1314 void ExynosVideoDecodeAccelerator::DequeueEvents() {
1315 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1316 DCHECK_EQ(decoder_state_, kDecoding);
1317 DVLOG(3) << "DequeueEvents()";
1318
1319 struct v4l2_event ev;
1320 memset(&ev, 0, sizeof(ev));
1321
1322 while (ioctl(mfc_fd_, VIDIOC_DQEVENT, &ev) == 0) {
1323 if (ev.type == V4L2_EVENT_RESOLUTION_CHANGE) {
1324 DVLOG(3) << "DequeueEvents(): got resolution change event.";
1325 DCHECK(!resolution_change_pending_);
1326 resolution_change_pending_ = true;
1327 }
1328 }
1329 }
1330
1183 void ExynosVideoDecodeAccelerator::DequeueMfc() { 1331 void ExynosVideoDecodeAccelerator::DequeueMfc() {
1184 DVLOG(3) << "DequeueMfc()"; 1332 DVLOG(3) << "DequeueMfc()";
1185 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1333 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1186 DCHECK_NE(decoder_state_, kUninitialized); 1334 DCHECK_NE(decoder_state_, kUninitialized);
1187 TRACE_EVENT0("Video Decoder", "EVDA::DequeueMfc"); 1335 TRACE_EVENT0("Video Decoder", "EVDA::DequeueMfc");
1188 1336
1189 // Dequeue completed MFC input (VIDEO_OUTPUT) buffers, and recycle to the free 1337 // Dequeue completed MFC input (VIDEO_OUTPUT) buffers, and recycle to the free
1190 // list. 1338 // list.
1191 struct v4l2_buffer dqbuf; 1339 struct v4l2_buffer dqbuf;
1192 struct v4l2_plane planes[2]; 1340 struct v4l2_plane planes[2];
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 << picture_buffer_id; 1679 << picture_buffer_id;
1532 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1680 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1533 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask"); 1681 TRACE_EVENT0("Video Decoder", "EVDA::ReusePictureBufferTask");
1534 1682
1535 // We run ReusePictureBufferTask even if we're in kResetting. 1683 // We run ReusePictureBufferTask even if we're in kResetting.
1536 if (decoder_state_ == kError) { 1684 if (decoder_state_ == kError) {
1537 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state"; 1685 DVLOG(2) << "ReusePictureBufferTask(): early out: kError state";
1538 return; 1686 return;
1539 } 1687 }
1540 1688
1689 if (decoder_state_ == kChangingResolution) {
1690 DVLOG(2) << "ReusePictureBufferTask(): early out: kChangingResolution";
1691 return;
1692 }
1693
1541 size_t index; 1694 size_t index;
1542 for (index = 0; index < gsc_output_buffer_map_.size(); ++index) 1695 for (index = 0; index < gsc_output_buffer_map_.size(); ++index)
1543 if (gsc_output_buffer_map_[index].picture_id == picture_buffer_id) 1696 if (gsc_output_buffer_map_[index].picture_id == picture_buffer_id)
1544 break; 1697 break;
1545 1698
1546 if (index >= gsc_output_buffer_map_.size()) { 1699 if (index >= gsc_output_buffer_map_.size()) {
1547 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found"; 1700 DLOG(ERROR) << "ReusePictureBufferTask(): picture_buffer_id not found";
1548 NOTIFY_ERROR(INVALID_ARGUMENT); 1701 NOTIFY_ERROR(INVALID_ARGUMENT);
1549 return; 1702 return;
1550 } 1703 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 decoder_delay_bitstream_buffer_id_) 1765 decoder_delay_bitstream_buffer_id_)
1613 return; 1766 return;
1614 } 1767 }
1615 if (decoder_current_input_buffer_ != -1) 1768 if (decoder_current_input_buffer_ != -1)
1616 return; 1769 return;
1617 if ((mfc_input_ready_queue_.size() + 1770 if ((mfc_input_ready_queue_.size() +
1618 mfc_input_buffer_queued_count_ + mfc_output_gsc_input_queue_.size() + 1771 mfc_input_buffer_queued_count_ + mfc_output_gsc_input_queue_.size() +
1619 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ ) != 0) 1772 gsc_input_buffer_queued_count_ + gsc_output_buffer_queued_count_ ) != 0)
1620 return; 1773 return;
1621 1774
1775 // TODO(posciak): crbug.com/270039. MFC requires a streamoff-streamon
1776 // sequence after flush to continue, even if we are not resetting. This would
1777 // make sense, because we don't really want to resume from a non-resume point
1778 // (e.g. not from an IDR) if we are flushed.
1779 // MSE player however triggers a Flush() on chunk end, but never Reset(). One
1780 // could argue either way, or even say that Flush() is not needed/harmful when
1781 // transitioning to next chunk.
1782 // For now, do the streamoff-streamon cycle to satisfy MFC and not freeze when
1783 // doing MSE. This should be harmless otherwise.
1784 if (!StopDevicePoll(false))
1785 return;
1786
1787 if (!StartDevicePoll())
1788 return;
1789
1622 decoder_delay_bitstream_buffer_id_ = -1; 1790 decoder_delay_bitstream_buffer_id_ = -1;
1623 decoder_flushing_ = false; 1791 decoder_flushing_ = false;
1624 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; 1792 DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush";
1625 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( 1793 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
1626 &Client::NotifyFlushDone, client_)); 1794 &Client::NotifyFlushDone, client_));
1627 1795
1628 // While we were flushing, we early-outed DecodeBufferTask()s. 1796 // While we were flushing, we early-outed DecodeBufferTask()s.
1629 ScheduleDecodeBufferTaskIfNeeded(); 1797 ScheduleDecodeBufferTaskIfNeeded();
1630 } 1798 }
1631 1799
1632 void ExynosVideoDecodeAccelerator::ResetTask() { 1800 void ExynosVideoDecodeAccelerator::ResetTask() {
sheu 2013/08/09 11:04:08 OK, this could be a little bad. What if we: 1. D
Pawel Osciak 2013/08/09 11:42:36 Added fix as per convo.
1633 DVLOG(3) << "ResetTask()"; 1801 DVLOG(3) << "ResetTask()";
1634 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1802 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1635 TRACE_EVENT0("Video Decoder", "EVDA::ResetTask"); 1803 TRACE_EVENT0("Video Decoder", "EVDA::ResetTask");
1636 1804
1637 if (decoder_state_ == kError) { 1805 if (decoder_state_ == kError) {
1638 DVLOG(2) << "ResetTask(): early out: kError state"; 1806 DVLOG(2) << "ResetTask(): early out: kError state";
1639 return; 1807 return;
1640 } 1808 }
1641 1809
1642 // We stop streaming, but we _don't_ destroy our buffers. 1810 // We stop streaming, but we _don't_ destroy our buffers.
sheu 2013/08/09 11:04:08 This comment is a little confusing now, with the '
Pawel Osciak 2013/08/09 11:42:36 Done.
1643 if (!StopDevicePoll()) 1811 if (!StopDevicePoll(false))
1644 return; 1812 return;
1645 1813
1814 DequeueEvents();
1815
1816 resolution_change_pending_ = false;
1646 decoder_current_bitstream_buffer_.reset(); 1817 decoder_current_bitstream_buffer_.reset();
1647 decoder_input_queue_.clear(); 1818 decoder_input_queue_.clear();
1648 1819
1649 decoder_current_input_buffer_ = -1; 1820 decoder_current_input_buffer_ = -1;
1650 1821
1651 // If we were flushing, we'll never return any more BitstreamBuffers or 1822 // If we were flushing, we'll never return any more BitstreamBuffers or
1652 // PictureBuffers; they have all been dropped and returned by now. 1823 // PictureBuffers; they have all been dropped and returned by now.
1653 NotifyFlushDoneIfNeeded(); 1824 NotifyFlushDoneIfNeeded();
1654 1825
1655 // Mark that we're resetting, then enqueue a ResetDoneTask(). All intervening 1826 // Mark that we're resetting, then enqueue a ResetDoneTask(). All intervening
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 ScheduleDecodeBufferTaskIfNeeded(); 1858 ScheduleDecodeBufferTaskIfNeeded();
1688 } 1859 }
1689 1860
1690 void ExynosVideoDecodeAccelerator::DestroyTask() { 1861 void ExynosVideoDecodeAccelerator::DestroyTask() {
1691 DVLOG(3) << "DestroyTask()"; 1862 DVLOG(3) << "DestroyTask()";
1692 TRACE_EVENT0("Video Decoder", "EVDA::DestroyTask"); 1863 TRACE_EVENT0("Video Decoder", "EVDA::DestroyTask");
1693 1864
1694 // DestroyTask() should run regardless of decoder_state_. 1865 // DestroyTask() should run regardless of decoder_state_.
1695 1866
1696 // Stop streaming and the device_poll_thread_. 1867 // Stop streaming and the device_poll_thread_.
1697 StopDevicePoll(); 1868 StopDevicePoll(false);
1698 1869
1699 decoder_current_bitstream_buffer_.reset(); 1870 decoder_current_bitstream_buffer_.reset();
1700 decoder_current_input_buffer_ = -1; 1871 decoder_current_input_buffer_ = -1;
1701 decoder_decode_buffer_tasks_scheduled_ = 0; 1872 decoder_decode_buffer_tasks_scheduled_ = 0;
1702 decoder_frames_at_client_ = 0; 1873 decoder_frames_at_client_ = 0;
1703 decoder_input_queue_.clear(); 1874 decoder_input_queue_.clear();
1704 decoder_flushing_ = false; 1875 decoder_flushing_ = false;
1705 1876
1706 // Set our state to kError. Just in case. 1877 // Set our state to kError. Just in case.
1707 decoder_state_ = kError; 1878 decoder_state_ = kError;
(...skipping 11 matching lines...) Expand all
1719 return false; 1890 return false;
1720 } 1891 }
1721 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 1892 device_poll_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
1722 &ExynosVideoDecodeAccelerator::DevicePollTask, 1893 &ExynosVideoDecodeAccelerator::DevicePollTask,
1723 base::Unretained(this), 1894 base::Unretained(this),
1724 0)); 1895 0));
1725 1896
1726 return true; 1897 return true;
1727 } 1898 }
1728 1899
1729 bool ExynosVideoDecodeAccelerator::StopDevicePoll() { 1900 bool ExynosVideoDecodeAccelerator::StopDevicePoll(bool keep_mfc_input) {
1730 DVLOG(3) << "StopDevicePoll()"; 1901 DVLOG(3) << "StopDevicePoll()";
1731 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); 1902 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current());
1732 1903
1733 // Signal the DevicePollTask() to stop, and stop the device poll thread. 1904 // Signal the DevicePollTask() to stop, and stop the device poll thread.
1734 if (!SetDevicePollInterrupt()) 1905 if (!SetDevicePollInterrupt())
1735 return false; 1906 return false;
1736 device_poll_thread_.Stop(); 1907 device_poll_thread_.Stop();
1737 // Clear the interrupt now, to be sure. 1908 // Clear the interrupt now, to be sure.
1738 if (!ClearDevicePollInterrupt()) 1909 if (!ClearDevicePollInterrupt())
1739 return false; 1910 return false;
1740 1911
1741 // Stop streaming. 1912 // Stop streaming.
1742 if (mfc_input_streamon_) { 1913 if (!keep_mfc_input) {
1743 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 1914 if (mfc_input_streamon_) {
1744 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); 1915 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1916 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type);
1917 }
1918 mfc_input_streamon_ = false;
1745 } 1919 }
1746 mfc_input_streamon_ = false;
1747 if (mfc_output_streamon_) { 1920 if (mfc_output_streamon_) {
1748 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1921 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1749 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type); 1922 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_STREAMOFF, &type);
1750 } 1923 }
1751 mfc_output_streamon_ = false; 1924 mfc_output_streamon_ = false;
1752 if (gsc_input_streamon_) { 1925 if (gsc_input_streamon_) {
1753 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 1926 __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1754 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type); 1927 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type);
1755 } 1928 }
1756 gsc_input_streamon_ = false; 1929 gsc_input_streamon_ = false;
1757 if (gsc_output_streamon_) { 1930 if (gsc_output_streamon_) {
1758 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1931 __u32 type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1759 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type); 1932 IOCTL_OR_ERROR_RETURN_FALSE(gsc_fd_, VIDIOC_STREAMOFF, &type);
1760 } 1933 }
1761 gsc_output_streamon_ = false; 1934 gsc_output_streamon_ = false;
1762 1935
1763 // Reset all our accounting info. 1936 // Reset all our accounting info.
1764 mfc_input_ready_queue_.clear(); 1937 if (!keep_mfc_input) {
1765 mfc_free_input_buffers_.clear(); 1938 mfc_input_ready_queue_.clear();
1766 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) { 1939 mfc_free_input_buffers_.clear();
1767 mfc_free_input_buffers_.push_back(i); 1940 for (size_t i = 0; i < mfc_input_buffer_map_.size(); ++i) {
1768 mfc_input_buffer_map_[i].at_device = false; 1941 mfc_free_input_buffers_.push_back(i);
1769 mfc_input_buffer_map_[i].bytes_used = 0; 1942 mfc_input_buffer_map_[i].at_device = false;
1770 mfc_input_buffer_map_[i].input_id = -1; 1943 mfc_input_buffer_map_[i].bytes_used = 0;
1944 mfc_input_buffer_map_[i].input_id = -1;
1945 }
1946 mfc_input_buffer_queued_count_ = 0;
1771 } 1947 }
1772 mfc_input_buffer_queued_count_ = 0;
1773 mfc_free_output_buffers_.clear(); 1948 mfc_free_output_buffers_.clear();
1774 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) { 1949 for (size_t i = 0; i < mfc_output_buffer_map_.size(); ++i) {
1775 mfc_free_output_buffers_.push_back(i); 1950 mfc_free_output_buffers_.push_back(i);
1776 mfc_output_buffer_map_[i].at_device = false; 1951 mfc_output_buffer_map_[i].at_device = false;
1777 mfc_output_buffer_map_[i].input_id = -1; 1952 mfc_output_buffer_map_[i].input_id = -1;
1778 } 1953 }
1779 mfc_output_buffer_queued_count_ = 0; 1954 mfc_output_buffer_queued_count_ = 0;
1780 mfc_output_gsc_input_queue_.clear(); 1955 mfc_output_gsc_input_queue_.clear();
1781 gsc_free_input_buffers_.clear(); 1956 gsc_free_input_buffers_.clear();
1782 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) { 1957 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 DVLOG(3) << "DevicePollTask()"; 2009 DVLOG(3) << "DevicePollTask()";
1835 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current()); 2010 DCHECK_EQ(device_poll_thread_.message_loop(), base::MessageLoop::current());
1836 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask"); 2011 TRACE_EVENT0("Video Decoder", "EVDA::DevicePollTask");
1837 2012
1838 // This routine just polls the set of device fds, and schedules a 2013 // This routine just polls the set of device fds, and schedules a
1839 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur. 2014 // ServiceDeviceTask() on decoder_thread_ when processing needs to occur.
1840 // Other threads may notify this task to return early by writing to 2015 // Other threads may notify this task to return early by writing to
1841 // device_poll_interrupt_fd_. 2016 // device_poll_interrupt_fd_.
1842 struct pollfd pollfds[3]; 2017 struct pollfd pollfds[3];
1843 nfds_t nfds; 2018 nfds_t nfds;
2019 int mfc_pollfd = -1;
1844 2020
1845 // Add device_poll_interrupt_fd_; 2021 // Add device_poll_interrupt_fd_;
1846 pollfds[0].fd = device_poll_interrupt_fd_; 2022 pollfds[0].fd = device_poll_interrupt_fd_;
1847 pollfds[0].events = POLLIN | POLLERR; 2023 pollfds[0].events = POLLIN | POLLERR;
1848 nfds = 1; 2024 nfds = 1;
1849 2025
1850 if (poll_fds & kPollMfc) { 2026 if (poll_fds & kPollMfc) {
1851 DVLOG(3) << "DevicePollTask(): adding MFC to poll() set"; 2027 DVLOG(3) << "DevicePollTask(): adding MFC to poll() set";
1852 pollfds[nfds].fd = mfc_fd_; 2028 pollfds[nfds].fd = mfc_fd_;
1853 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR; 2029 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR | POLLPRI;
2030 mfc_pollfd = nfds;
1854 nfds++; 2031 nfds++;
1855 } 2032 }
1856 // Add GSC fd, if we should poll on it. 2033 // Add GSC fd, if we should poll on it.
1857 // GSC has to wait until both input and output buffers are queued. 2034 // GSC has to wait until both input and output buffers are queued.
1858 if (poll_fds & kPollGsc) { 2035 if (poll_fds & kPollGsc) {
1859 DVLOG(3) << "DevicePollTask(): adding GSC to poll() set"; 2036 DVLOG(3) << "DevicePollTask(): adding GSC to poll() set";
1860 pollfds[nfds].fd = gsc_fd_; 2037 pollfds[nfds].fd = gsc_fd_;
1861 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR; 2038 pollfds[nfds].events = POLLIN | POLLOUT | POLLERR;
1862 nfds++; 2039 nfds++;
1863 } 2040 }
1864 2041
1865 // Poll it! 2042 // Poll it!
1866 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { 2043 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) {
1867 DPLOG(ERROR) << "DevicePollTask(): poll() failed"; 2044 DPLOG(ERROR) << "DevicePollTask(): poll() failed";
1868 NOTIFY_ERROR(PLATFORM_FAILURE); 2045 NOTIFY_ERROR(PLATFORM_FAILURE);
1869 return; 2046 return;
1870 } 2047 }
1871 2048
2049 bool event_pending = (mfc_pollfd != -1 &&
2050 pollfds[mfc_pollfd].revents & POLLPRI);
2051
1872 // All processing should happen on ServiceDeviceTask(), since we shouldn't 2052 // All processing should happen on ServiceDeviceTask(), since we shouldn't
1873 // touch decoder state from this thread. 2053 // touch decoder state from this thread.
1874 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 2054 decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
1875 &ExynosVideoDecodeAccelerator::ServiceDeviceTask, 2055 &ExynosVideoDecodeAccelerator::ServiceDeviceTask,
1876 base::Unretained(this))); 2056 base::Unretained(this), event_pending));
1877 } 2057 }
1878 2058
1879 void ExynosVideoDecodeAccelerator::NotifyError(Error error) { 2059 void ExynosVideoDecodeAccelerator::NotifyError(Error error) {
1880 DVLOG(2) << "NotifyError()"; 2060 DVLOG(2) << "NotifyError()";
1881 2061
1882 if (!child_message_loop_proxy_->BelongsToCurrentThread()) { 2062 if (!child_message_loop_proxy_->BelongsToCurrentThread()) {
1883 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( 2063 child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
1884 &ExynosVideoDecodeAccelerator::NotifyError, weak_this_, error)); 2064 &ExynosVideoDecodeAccelerator::NotifyError, weak_this_, error));
1885 return; 2065 return;
1886 } 2066 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 } 2142 }
1963 mfc_input_buffer_map_[i].address = address; 2143 mfc_input_buffer_map_[i].address = address;
1964 mfc_input_buffer_map_[i].length = buffer.m.planes[0].length; 2144 mfc_input_buffer_map_[i].length = buffer.m.planes[0].length;
1965 } 2145 }
1966 2146
1967 return true; 2147 return true;
1968 } 2148 }
1969 2149
1970 bool ExynosVideoDecodeAccelerator::CreateMfcOutputBuffers() { 2150 bool ExynosVideoDecodeAccelerator::CreateMfcOutputBuffers() {
1971 DVLOG(3) << "CreateMfcOutputBuffers()"; 2151 DVLOG(3) << "CreateMfcOutputBuffers()";
1972 DCHECK_EQ(decoder_state_, kInitialized); 2152 DCHECK(decoder_state_ == kInitialized ||
2153 decoder_state_ == kChangingResolution);
1973 DCHECK(!mfc_output_streamon_); 2154 DCHECK(!mfc_output_streamon_);
1974 DCHECK(mfc_output_buffer_map_.empty()); 2155 DCHECK(mfc_output_buffer_map_.empty());
1975 2156
1976 // Number of MFC output buffers we need. 2157 // Number of MFC output buffers we need.
1977 struct v4l2_control ctrl; 2158 struct v4l2_control ctrl;
1978 memset(&ctrl, 0, sizeof(ctrl)); 2159 memset(&ctrl, 0, sizeof(ctrl));
1979 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; 2160 ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE;
1980 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_G_CTRL, &ctrl); 2161 IOCTL_OR_ERROR_RETURN_FALSE(mfc_fd_, VIDIOC_G_CTRL, &ctrl);
1981 mfc_output_dpb_size_ = ctrl.value; 2162 mfc_output_dpb_size_ = ctrl.value;
1982 2163
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 mfc_output_buffer_map_[i].address[j] = address; 2200 mfc_output_buffer_map_[i].address[j] = address;
2020 mfc_output_buffer_map_[i].length[j] = buffer.m.planes[j].length; 2201 mfc_output_buffer_map_[i].length[j] = buffer.m.planes[j].length;
2021 } 2202 }
2022 } 2203 }
2023 2204
2024 return true; 2205 return true;
2025 } 2206 }
2026 2207
2027 bool ExynosVideoDecodeAccelerator::CreateGscInputBuffers() { 2208 bool ExynosVideoDecodeAccelerator::CreateGscInputBuffers() {
2028 DVLOG(3) << "CreateGscInputBuffers()"; 2209 DVLOG(3) << "CreateGscInputBuffers()";
2029 DCHECK_EQ(decoder_state_, kInitialized); 2210 DCHECK(decoder_state_ == kInitialized ||
2211 decoder_state_ == kChangingResolution);
2030 DCHECK(!gsc_input_streamon_); 2212 DCHECK(!gsc_input_streamon_);
2031 DCHECK(gsc_input_buffer_map_.empty()); 2213 DCHECK(gsc_input_buffer_map_.empty());
2032 2214
2033 struct v4l2_format format; 2215 struct v4l2_format format;
2034 memset(&format, 0, sizeof(format)); 2216 memset(&format, 0, sizeof(format));
2035 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 2217 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
2036 format.fmt.pix_mp.width = frame_buffer_size_.width(); 2218 format.fmt.pix_mp.width = frame_buffer_size_.width();
2037 format.fmt.pix_mp.height = frame_buffer_size_.height(); 2219 format.fmt.pix_mp.height = frame_buffer_size_.height();
2038 format.fmt.pix_mp.pixelformat = mfc_output_buffer_pixelformat_; 2220 format.fmt.pix_mp.pixelformat = mfc_output_buffer_pixelformat_;
2039 format.fmt.pix_mp.plane_fmt[0].sizeimage = mfc_output_buffer_size_[0]; 2221 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
2082 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) { 2264 for (size_t i = 0; i < gsc_input_buffer_map_.size(); ++i) {
2083 gsc_free_input_buffers_.push_back(i); 2265 gsc_free_input_buffers_.push_back(i);
2084 gsc_input_buffer_map_[i].mfc_output = -1; 2266 gsc_input_buffer_map_[i].mfc_output = -1;
2085 } 2267 }
2086 2268
2087 return true; 2269 return true;
2088 } 2270 }
2089 2271
2090 bool ExynosVideoDecodeAccelerator::CreateGscOutputBuffers() { 2272 bool ExynosVideoDecodeAccelerator::CreateGscOutputBuffers() {
2091 DVLOG(3) << "CreateGscOutputBuffers()"; 2273 DVLOG(3) << "CreateGscOutputBuffers()";
2092 DCHECK_EQ(decoder_state_, kInitialized); 2274 DCHECK(decoder_state_ == kInitialized ||
2275 decoder_state_ == kChangingResolution);
2093 DCHECK(!gsc_output_streamon_); 2276 DCHECK(!gsc_output_streamon_);
2094 DCHECK(gsc_output_buffer_map_.empty()); 2277 DCHECK(gsc_output_buffer_map_.empty());
2095 2278
2096 // GSC outputs into the EGLImages we create from the textures we are 2279 // GSC outputs into the EGLImages we create from the textures we are
2097 // assigned. Assume RGBA8888 format. 2280 // assigned. Assume RGBA8888 format.
2098 struct v4l2_format format; 2281 struct v4l2_format format;
2099 memset(&format, 0, sizeof(format)); 2282 memset(&format, 0, sizeof(format));
2100 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 2283 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2101 format.fmt.pix_mp.width = frame_buffer_size_.width(); 2284 format.fmt.pix_mp.width = frame_buffer_size_.width();
2102 format.fmt.pix_mp.height = frame_buffer_size_.height(); 2285 format.fmt.pix_mp.height = frame_buffer_size_.height();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 2392
2210 size_t i = 0; 2393 size_t i = 0;
2211 do { 2394 do {
2212 GscOutputRecord& output_record = gsc_output_buffer_map_[i]; 2395 GscOutputRecord& output_record = gsc_output_buffer_map_[i];
2213 if (output_record.fd != -1) 2396 if (output_record.fd != -1)
2214 HANDLE_EINTR(close(output_record.fd)); 2397 HANDLE_EINTR(close(output_record.fd));
2215 if (output_record.egl_image != EGL_NO_IMAGE_KHR) 2398 if (output_record.egl_image != EGL_NO_IMAGE_KHR)
2216 eglDestroyImageKHR(egl_display_, output_record.egl_image); 2399 eglDestroyImageKHR(egl_display_, output_record.egl_image);
2217 if (output_record.egl_sync != EGL_NO_SYNC_KHR) 2400 if (output_record.egl_sync != EGL_NO_SYNC_KHR)
2218 eglDestroySyncKHR(egl_display_, output_record.egl_sync); 2401 eglDestroySyncKHR(egl_display_, output_record.egl_sync);
2219 if (client_) 2402 if (client_) {
2403 DVLOG(1) << "DestroyGscOutputBuffers(): "
2404 << "dismissing PictureBuffer id=" << output_record.picture_id;
2220 client_->DismissPictureBuffer(output_record.picture_id); 2405 client_->DismissPictureBuffer(output_record.picture_id);
2406 }
2221 ++i; 2407 ++i;
2222 } while (i < gsc_output_buffer_map_.size()); 2408 } while (i < gsc_output_buffer_map_.size());
2223 } 2409 }
2224 2410
2225 struct v4l2_requestbuffers reqbufs; 2411 struct v4l2_requestbuffers reqbufs;
2226 memset(&reqbufs, 0, sizeof(reqbufs)); 2412 memset(&reqbufs, 0, sizeof(reqbufs));
2227 reqbufs.count = 0; 2413 reqbufs.count = 0;
2228 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 2414 reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
2229 reqbufs.memory = V4L2_MEMORY_DMABUF; 2415 reqbufs.memory = V4L2_MEMORY_DMABUF;
2230 if (ioctl(gsc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0) 2416 if (ioctl(gsc_fd_, VIDIOC_REQBUFS, &reqbufs) != 0)
2231 DPLOG(ERROR) << "DestroyGscOutputBuffers(): ioctl() failed: VIDIOC_REQBUFS"; 2417 DPLOG(ERROR) << "DestroyGscOutputBuffers(): ioctl() failed: VIDIOC_REQBUFS";
2232 2418
2233 gsc_output_buffer_map_.clear(); 2419 gsc_output_buffer_map_.clear();
2234 gsc_free_output_buffers_.clear(); 2420 gsc_free_output_buffers_.clear();
2235 } 2421 }
2236 2422
2237 } // namespace content 2423 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698