| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_TOOLS_PLAYER_WTL_VIEW_H_ | 5 #ifndef MEDIA_TOOLS_PLAYER_WTL_VIEW_H_ |
| 6 #define MEDIA_TOOLS_PLAYER_WTL_VIEW_H_ | 6 #define MEDIA_TOOLS_PLAYER_WTL_VIEW_H_ |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <process.h> | 9 #include <process.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include "media/base/buffers.h" | 12 #include "media/base/video_frame.h" |
| 13 #include "media/base/yuv_convert.h" | 13 #include "media/base/yuv_convert.h" |
| 14 #include "media/tools/player_wtl/movie.h" | 14 #include "media/tools/player_wtl/movie.h" |
| 15 #include "media/tools/player_wtl/player_wtl.h" | 15 #include "media/tools/player_wtl/player_wtl.h" |
| 16 #include "media/tools/player_wtl/wtl_renderer.h" | 16 #include "media/tools/player_wtl/wtl_renderer.h" |
| 17 | 17 |
| 18 // Fetchs current time as milliseconds. | 18 // Fetchs current time as milliseconds. |
| 19 // Returns as double for high duration and precision. | 19 // Returns as double for high duration and precision. |
| 20 inline double GetTime() { | 20 inline double GetTime() { |
| 21 LARGE_INTEGER perf_time, perf_hz; | 21 LARGE_INTEGER perf_time, perf_hz; |
| 22 QueryPerformanceFrequency(&perf_hz); // May change with speed step. | 22 QueryPerformanceFrequency(&perf_hz); // May change with speed step. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 if (!bmp_.IsNull()) { | 115 if (!bmp_.IsNull()) { |
| 116 dc.MoveTo(size_.cx, 0); | 116 dc.MoveTo(size_.cx, 0); |
| 117 dc.LineTo(size_.cx, size_.cy); | 117 dc.LineTo(size_.cx, size_.cy); |
| 118 dc.LineTo(0, size_.cy); | 118 dc.LineTo(0, size_.cy); |
| 119 } | 119 } |
| 120 return 0; | 120 return 0; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Convert the video frame to RGB and Blit. | 123 // Convert the video frame to RGB and Blit. |
| 124 void ConvertFrame(media::VideoFrame * video_frame) { | 124 void ConvertFrame(media::VideoFrame* video_frame) { |
| 125 media::VideoSurface frame_in; | |
| 126 bool lock_result = video_frame->Lock(&frame_in); | |
| 127 DCHECK(lock_result); | |
| 128 BITMAP bm; | 125 BITMAP bm; |
| 129 bmp_.GetBitmap(&bm); | 126 bmp_.GetBitmap(&bm); |
| 130 int dibwidth = bm.bmWidth; | 127 int dibwidth = bm.bmWidth; |
| 131 int dibheight = bm.bmHeight; | 128 int dibheight = bm.bmHeight; |
| 132 | 129 |
| 133 uint8 *movie_dib_bits = reinterpret_cast<uint8 *>(bm.bmBits) + | 130 uint8 *movie_dib_bits = reinterpret_cast<uint8 *>(bm.bmBits) + |
| 134 bm.bmWidthBytes * (bm.bmHeight - 1); | 131 bm.bmWidthBytes * (bm.bmHeight - 1); |
| 135 int dibrowbytes = -bm.bmWidthBytes; | 132 int dibrowbytes = -bm.bmWidthBytes; |
| 136 int clipped_width = frame_in.width; | 133 int clipped_width = video_frame->width(); |
| 137 if (dibwidth < clipped_width) { | 134 if (dibwidth < clipped_width) { |
| 138 clipped_width = dibwidth; | 135 clipped_width = dibwidth; |
| 139 } | 136 } |
| 140 int clipped_height = frame_in.height; | 137 int clipped_height = video_frame->height(); |
| 141 if (dibheight < clipped_height) { | 138 if (dibheight < clipped_height) { |
| 142 clipped_height = dibheight; | 139 clipped_height = dibheight; |
| 143 } | 140 } |
| 144 | 141 |
| 145 int scaled_width = clipped_width; | 142 int scaled_width = clipped_width; |
| 146 int scaled_height = clipped_height; | 143 int scaled_height = clipped_height; |
| 147 switch (view_size_) { | 144 switch (view_size_) { |
| 148 case 0: | 145 case 0: |
| 149 scaled_width = clipped_width / 4; | 146 scaled_width = clipped_width / 4; |
| 150 scaled_height = clipped_height / 4; | 147 scaled_height = clipped_height / 4; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 179 scaled_width = clipped_width; | 176 scaled_width = clipped_width; |
| 180 scaled_height = clipped_height; | 177 scaled_height = clipped_height; |
| 181 clipped_width = scaled_width / 4; | 178 clipped_width = scaled_width / 4; |
| 182 clipped_height = scaled_height / 4; | 179 clipped_height = scaled_height / 4; |
| 183 break; | 180 break; |
| 184 } | 181 } |
| 185 | 182 |
| 186 // Append each frame to end of file. | 183 // Append each frame to end of file. |
| 187 bool enable_dump_yuv_file = media::Movie::get()->GetDumpYuvFileEnable(); | 184 bool enable_dump_yuv_file = media::Movie::get()->GetDumpYuvFileEnable(); |
| 188 if (enable_dump_yuv_file) { | 185 if (enable_dump_yuv_file) { |
| 189 DumpYUV(frame_in); | 186 DumpYUV(video_frame); |
| 190 } | 187 } |
| 191 | 188 |
| 192 #ifdef TESTING | 189 #ifdef TESTING |
| 193 double yuv_time_start = GetTime(); // Start timer. | 190 double yuv_time_start = GetTime(); // Start timer. |
| 194 #endif | 191 #endif |
| 195 | 192 |
| 196 bool enable_draw = media::Movie::get()->GetDrawEnable(); | 193 bool enable_draw = media::Movie::get()->GetDrawEnable(); |
| 197 if (enable_draw) { | 194 if (enable_draw) { |
| 198 DCHECK(bm.bmBitsPixel == 32); | 195 DCHECK(bm.bmBitsPixel == 32); |
| 199 DrawYUV(frame_in, | 196 DrawYUV(video_frame, |
| 200 movie_dib_bits, | 197 movie_dib_bits, |
| 201 dibrowbytes, | 198 dibrowbytes, |
| 202 clipped_width, | 199 clipped_width, |
| 203 clipped_height, | 200 clipped_height, |
| 204 scaled_width, | 201 scaled_width, |
| 205 scaled_height); | 202 scaled_height); |
| 206 } | 203 } |
| 207 #ifdef TESTING | 204 #ifdef TESTING |
| 208 double yuv_time_end = GetTime(); | 205 double yuv_time_end = GetTime(); |
| 209 static int yuv_time_count = 0; | 206 static int yuv_time_count = 0; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 private: | 334 private: |
| 338 HBITMAP hbmp_; // For Images | 335 HBITMAP hbmp_; // For Images |
| 339 // View Size: 0=1/4, 1=0.5, 2=normal, 3=2x, 4=3x, 5=4x, 3=fit, 4=full. | 336 // View Size: 0=1/4, 1=0.5, 2=normal, 3=2x, 4=3x, 5=4x, 3=fit, 4=full. |
| 340 int view_size_; | 337 int view_size_; |
| 341 | 338 |
| 342 // View Rotate 0-5 for ID_VIEW_ROTATE0 to ID_VIEW_MIRROR_VERTICAL | 339 // View Rotate 0-5 for ID_VIEW_ROTATE0 to ID_VIEW_MIRROR_VERTICAL |
| 343 media::Rotate view_rotate_; | 340 media::Rotate view_rotate_; |
| 344 | 341 |
| 345 // Draw a frame of YUV to an RGB buffer with scaling. | 342 // Draw a frame of YUV to an RGB buffer with scaling. |
| 346 // Handles different YUV formats. | 343 // Handles different YUV formats. |
| 347 void DrawYUV(const media::VideoSurface &frame_in, | 344 void DrawYUV(const media::VideoFrame* video_frame, |
| 348 uint8 *movie_dib_bits, | 345 uint8 *movie_dib_bits, |
| 349 int dibrowbytes, | 346 int dibrowbytes, |
| 350 int clipped_width, | 347 int clipped_width, |
| 351 int clipped_height, | 348 int clipped_height, |
| 352 int scaled_width, | 349 int scaled_width, |
| 353 int scaled_height) { | 350 int scaled_height) { |
| 354 media::YUVType yuv_type = (frame_in.format == media::VideoSurface::YV12) ? | 351 media::YUVType yuv_type = |
| 355 media::YV12 : media::YV16; | 352 (video_frame->format() == media::VideoFrame::YV12) ? |
| 353 media::YV12 : media::YV16; |
| 356 | 354 |
| 357 // Simple convert is not necessary for performance, but allows | 355 // Simple convert is not necessary for performance, but allows |
| 358 // easier alternative implementations. | 356 // easier alternative implementations. |
| 359 if ((view_rotate_ == media::ROTATE_0) && // Not scaled or rotated | 357 if ((view_rotate_ == media::ROTATE_0) && // Not scaled or rotated |
| 360 (view_size_ == 2)) { | 358 (view_size_ == 2)) { |
| 361 media::ConvertYUVToRGB32(frame_in.data[0], | 359 media::ConvertYUVToRGB32(video_frame->data(0), |
| 362 frame_in.data[1], | 360 video_frame->data(1), |
| 363 frame_in.data[2], | 361 video_frame->data(2), |
| 364 movie_dib_bits, | 362 movie_dib_bits, |
| 365 scaled_width, scaled_height, | 363 scaled_width, scaled_height, |
| 366 frame_in.strides[0], | 364 video_frame->stride(0), |
| 367 frame_in.strides[1], | 365 video_frame->stride(1), |
| 368 dibrowbytes, | 366 dibrowbytes, |
| 369 yuv_type); | 367 yuv_type); |
| 370 } else { | 368 } else { |
| 371 media::ScaleYUVToRGB32(frame_in.data[0], | 369 media::ScaleYUVToRGB32(video_frame->data(0), |
| 372 frame_in.data[1], | 370 video_frame->data(1), |
| 373 frame_in.data[2], | 371 video_frame->data(2), |
| 374 movie_dib_bits, | 372 movie_dib_bits, |
| 375 clipped_width, clipped_height, | 373 clipped_width, clipped_height, |
| 376 scaled_width, scaled_height, | 374 scaled_width, scaled_height, |
| 377 frame_in.strides[0], | 375 video_frame->stride(0), |
| 378 frame_in.strides[1], | 376 video_frame->stride(1), |
| 379 dibrowbytes, | 377 dibrowbytes, |
| 380 yuv_type, | 378 yuv_type, |
| 381 view_rotate_); | 379 view_rotate_); |
| 382 } | 380 } |
| 383 } | 381 } |
| 384 | 382 |
| 385 // Diagnostic function to write out YUV in format compatible with PYUV tool. | 383 // Diagnostic function to write out YUV in format compatible with PYUV tool. |
| 386 void DumpYUV(const media::VideoSurface &frame_in) { | 384 void DumpYUV(const media::VideoFrame* video_frame) { |
| 387 FILE * file_yuv = fopen("raw.yuv", "ab+"); // Open for append binary. | 385 FILE * file_yuv = fopen("raw.yuv", "ab+"); // Open for append binary. |
| 388 if (file_yuv != NULL) { | 386 if (file_yuv != NULL) { |
| 389 fseek(file_yuv, 0, SEEK_END); | 387 fseek(file_yuv, 0, SEEK_END); |
| 390 const size_t frame_size = frame_in.width * frame_in.height; | 388 const size_t frame_size = |
| 391 for (size_t y = 0; y < frame_in.height; ++y) | 389 video_frame->width() * video_frame->height(); |
| 392 fwrite(frame_in.data[0]+frame_in.strides[0]*y, | 390 for (size_t y = 0; y < video_frame->height(); ++y) |
| 393 frame_in.width, sizeof(uint8), file_yuv); | 391 fwrite(video_frame->data(0) + video_frame->stride(0)*y, |
| 394 for (size_t y = 0; y < frame_in.height/2; ++y) | 392 video_frame->width(), sizeof(uint8), file_yuv); |
| 395 fwrite(frame_in.data[1]+frame_in.strides[1]*y, | 393 for (size_t y = 0; y < video_frame->height()/2; ++y) |
| 396 frame_in.width/2, sizeof(uint8), file_yuv); | 394 fwrite(video_frame->data(1) + video_frame->stride(1)*y, |
| 397 for (size_t y = 0; y < frame_in.height/2; ++y) | 395 video_frame->width() / 2, sizeof(uint8), file_yuv); |
| 398 fwrite(frame_in.data[2]+frame_in.strides[2]*y, | 396 for (size_t y = 0; y < video_frame->height()/2; ++y) |
| 399 frame_in.width/2, sizeof(uint8), file_yuv); | 397 fwrite(video_frame->data(2) + video_frame->stride(2)*y, |
| 398 video_frame->width() / 2, sizeof(uint8), file_yuv); |
| 400 fclose(file_yuv); | 399 fclose(file_yuv); |
| 401 | 400 |
| 402 #if TESTING | 401 #if TESTING |
| 403 static int frame_dump_count = 0; | 402 static int frame_dump_count = 0; |
| 404 char outputbuf[512]; | 403 char outputbuf[512]; |
| 405 _snprintf_s(outputbuf, sizeof(outputbuf), "yuvdump %4d %dx%d stride %d\n", | 404 _snprintf_s(outputbuf, sizeof(outputbuf), "yuvdump %4d %dx%d stride %d\n", |
| 406 frame_dump_count, frame_in.width, frame_in.height, | 405 frame_dump_count, video_frame->width(), |
| 407 frame_in.strides[0]); | 406 video_frame->height(), |
| 407 video_frame->stride(0)); |
| 408 OutputDebugStringA(outputbuf); | 408 OutputDebugStringA(outputbuf); |
| 409 ++frame_dump_count; | 409 ++frame_dump_count; |
| 410 #endif | 410 #endif |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 media::VideoFrame* last_frame_; | 414 media::VideoFrame* last_frame_; |
| 415 base::TimeDelta last_timestamp_; | 415 base::TimeDelta last_timestamp_; |
| 416 | 416 |
| 417 DISALLOW_COPY_AND_ASSIGN(WtlVideoWindow); | 417 DISALLOW_COPY_AND_ASSIGN(WtlVideoWindow); |
| 418 }; | 418 }; |
| 419 | 419 |
| 420 #endif // MEDIA_TOOLS_PLAYER_WTL_VIEW_H_ | 420 #endif // MEDIA_TOOLS_PLAYER_WTL_VIEW_H_ |
| OLD | NEW |