| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/capture/video/file_video_capture_device.h" | 5 #include "media/capture/video/file_video_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "media/capture/video_capture_types.h" | 18 #include "media/capture/video_capture_types.h" |
| 19 #include "media/filters/jpeg_parser.h" | 19 #include "media/filters/jpeg_parser.h" |
| 20 | 20 |
| 21 namespace media { | 21 namespace media { |
| 22 | 22 |
| 23 static const int kY4MHeaderMaxSize = 200; | 23 static const int kY4MHeaderMaxSize = 200; |
| 24 static const char kY4MSimpleFrameDelimiter[] = "FRAME"; | 24 static const char kY4MSimpleFrameDelimiter[] = "FRAME"; |
| 25 static const int kY4MSimpleFrameDelimiterSize = 6; | 25 static const int kY4MSimpleFrameDelimiterSize = 6; |
| 26 static const float kMJpegFrameRate = 30.0f; | 26 static const float kMJpegFrameRate = 30.0f; |
| 27 | 27 |
| 28 int ParseY4MInt(const base::StringPiece& token) { | 28 int ParseY4MInt(const base::StringPiece& token) { |
| 29 int temp_int; | 29 int temp_int; |
| 30 CHECK(base::StringToInt(token, &temp_int)) << token; | 30 CHECK(base::StringToInt(token, &temp_int)); |
| 31 return temp_int; | 31 return temp_int; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Extract numerator and denominator out of a token that must have the aspect | 34 // Extract numerator and denominator out of a token that must have the aspect |
| 35 // numerator:denominator, both integer numbers. | 35 // numerator:denominator, both integer numbers. |
| 36 void ParseY4MRational(const base::StringPiece& token, | 36 void ParseY4MRational(const base::StringPiece& token, |
| 37 int* numerator, int* denominator) { | 37 int* numerator, int* denominator) { |
| 38 size_t index_divider = token.find(':'); | 38 size_t index_divider = token.find(':'); |
| 39 CHECK_NE(index_divider, token.npos); | 39 CHECK_NE(index_divider, token.npos); |
| 40 *numerator = ParseY4MInt(token.substr(0, index_divider)); | 40 *numerator = ParseY4MInt(token.substr(0, index_divider)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 break; | 84 break; |
| 85 } | 85 } |
| 86 case 'I': | 86 case 'I': |
| 87 // Interlacing is ignored, but we don't like mixed modes. | 87 // Interlacing is ignored, but we don't like mixed modes. |
| 88 CHECK_NE(token[0], 'm'); | 88 CHECK_NE(token[0], 'm'); |
| 89 break; | 89 break; |
| 90 case 'A': | 90 case 'A': |
| 91 // Pixel aspect ratio ignored. | 91 // Pixel aspect ratio ignored. |
| 92 break; | 92 break; |
| 93 case 'C': | 93 case 'C': |
| 94 CHECK(token == "420" || token == "420jpeg" || token == "420paldv") | 94 CHECK(token == "420" || token == "420jpeg" || |
| 95 << token; // Only I420 is supported, and we fudge the variants. | 95 token == "420paldv"); // Only I420 is supported, and we fudge the |
| 96 // variants. |
| 96 break; | 97 break; |
| 97 default: | 98 default: |
| 98 break; | 99 break; |
| 99 } | 100 } |
| 100 // We're done if we have found a newline character right after the token. | 101 // We're done if we have found a newline character right after the token. |
| 101 if (file_header[blank_position] == '\n') | 102 if (file_header[blank_position] == '\n') |
| 102 break; | 103 break; |
| 103 index = blank_position + 1; | 104 index = blank_position + 1; |
| 104 } | 105 } |
| 105 // Last video format semantic correctness check before sending it back. | 106 // Last video format semantic correctness check before sending it back. |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 if (next_frame_time_ < current_time) | 387 if (next_frame_time_ < current_time) |
| 387 next_frame_time_ = current_time; | 388 next_frame_time_ = current_time; |
| 388 } | 389 } |
| 389 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 390 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 390 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, | 391 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, |
| 391 base::Unretained(this)), | 392 base::Unretained(this)), |
| 392 next_frame_time_ - current_time); | 393 next_frame_time_ - current_time); |
| 393 } | 394 } |
| 394 | 395 |
| 395 } // namespace media | 396 } // namespace media |
| OLD | NEW |