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/base/media_file_checker.h" | 5 #include "media/base/media_file_checker.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "media/ffmpeg/ffmpeg_common.h" | 11 #include "media/ffmpeg/ffmpeg_common.h" |
12 #include "media/filters/blocking_url_protocol.h" | 12 #include "media/filters/blocking_url_protocol.h" |
13 #include "media/filters/ffmpeg_glue.h" | 13 #include "media/filters/ffmpeg_glue.h" |
14 #include "media/filters/file_data_source.h" | 14 #include "media/filters/file_data_source.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 static const int64 kMaxCheckTimeInSeconds = 5; | 18 static const int64 kMaxCheckTimeInSeconds = 5; |
19 | 19 |
20 static void OnError(bool* called) { | 20 static void OnError(bool* called) { |
21 *called = false; | 21 *called = false; |
22 } | 22 } |
23 | 23 |
24 MediaFileChecker::MediaFileChecker(const base::PlatformFile& file) | 24 MediaFileChecker::MediaFileChecker(base::File file) : file_(file.Pass()) { |
25 : file_(file), | |
26 file_closer_(&file_) { | |
27 } | 25 } |
28 | 26 |
29 MediaFileChecker::~MediaFileChecker() { | 27 MediaFileChecker::~MediaFileChecker() { |
30 } | 28 } |
31 | 29 |
32 bool MediaFileChecker::Start(base::TimeDelta check_time) { | 30 bool MediaFileChecker::Start(base::TimeDelta check_time) { |
33 media::FileDataSource source; | 31 media::FileDataSource source(file_.Pass()); |
34 bool read_ok = true; | 32 bool read_ok = true; |
35 media::BlockingUrlProtocol protocol(&source, base::Bind(&OnError, &read_ok)); | 33 media::BlockingUrlProtocol protocol(&source, base::Bind(&OnError, &read_ok)); |
36 media::FFmpegGlue glue(&protocol); | 34 media::FFmpegGlue glue(&protocol); |
37 source.InitializeFromPlatformFile(file_); | |
38 AVFormatContext* format_context = glue.format_context(); | 35 AVFormatContext* format_context = glue.format_context(); |
39 | 36 |
40 if (!glue.OpenContext()) | 37 if (!glue.OpenContext()) |
41 return false; | 38 return false; |
42 | 39 |
43 if (avformat_find_stream_info(format_context, NULL) < 0) | 40 if (avformat_find_stream_info(format_context, NULL) < 0) |
44 return false; | 41 return false; |
45 | 42 |
46 // Remember the codec context for any decodable audio or video streams. | 43 // Remember the codec context for any decodable audio or video streams. |
47 std::map<int, AVCodecContext*> stream_contexts; | 44 std::map<int, AVCodecContext*> stream_contexts; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 result = avcodec_decode_video2(av_context, frame.get(), &frame_decoded, | 98 result = avcodec_decode_video2(av_context, frame.get(), &frame_decoded, |
102 &packet); | 99 &packet); |
103 } | 100 } |
104 av_free_packet(&packet); | 101 av_free_packet(&packet); |
105 } while (base::Time::Now() < deadline && read_ok && result >= 0); | 102 } while (base::Time::Now() < deadline && read_ok && result >= 0); |
106 | 103 |
107 return read_ok && (result == AVERROR_EOF || result >= 0); | 104 return read_ok && (result == AVERROR_EOF || result >= 0); |
108 } | 105 } |
109 | 106 |
110 } // namespace media | 107 } // namespace media |
OLD | NEW |