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" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 continue; | 77 continue; |
78 } | 78 } |
79 AVCodecContext* av_context = it->second; | 79 AVCodecContext* av_context = it->second; |
80 | 80 |
81 int frame_decoded = 0; | 81 int frame_decoded = 0; |
82 if (av_context->codec_type == AVMEDIA_TYPE_AUDIO) { | 82 if (av_context->codec_type == AVMEDIA_TYPE_AUDIO) { |
83 // A shallow copy of packet so we can slide packet.data as frames are | 83 // A shallow copy of packet so we can slide packet.data as frames are |
84 // decoded; otherwise av_free_packet() will corrupt memory. | 84 // decoded; otherwise av_free_packet() will corrupt memory. |
85 AVPacket temp_packet = packet; | 85 AVPacket temp_packet = packet; |
86 do { | 86 do { |
87 avcodec_get_frame_defaults(frame.get()); | |
88 result = avcodec_decode_audio4(av_context, frame.get(), &frame_decoded, | 87 result = avcodec_decode_audio4(av_context, frame.get(), &frame_decoded, |
89 &temp_packet); | 88 &temp_packet); |
90 if (result < 0) | 89 if (result < 0) |
91 break; | 90 break; |
| 91 av_frame_unref(frame.get()); |
92 temp_packet.size -= result; | 92 temp_packet.size -= result; |
93 temp_packet.data += result; | 93 temp_packet.data += result; |
| 94 frame_decoded = 0; |
94 } while (temp_packet.size > 0); | 95 } while (temp_packet.size > 0); |
95 } else if (av_context->codec_type == AVMEDIA_TYPE_VIDEO) { | 96 } else if (av_context->codec_type == AVMEDIA_TYPE_VIDEO) { |
96 avcodec_get_frame_defaults(frame.get()); | |
97 result = avcodec_decode_video2(av_context, frame.get(), &frame_decoded, | 97 result = avcodec_decode_video2(av_context, frame.get(), &frame_decoded, |
98 &packet); | 98 &packet); |
| 99 if (result >= 0 && frame_decoded) |
| 100 av_frame_unref(frame.get()); |
99 } | 101 } |
100 av_free_packet(&packet); | 102 av_free_packet(&packet); |
101 } while (base::TimeTicks::Now() < deadline && read_ok && result >= 0); | 103 } while (base::TimeTicks::Now() < deadline && read_ok && result >= 0); |
102 | 104 |
103 return read_ok && (result == AVERROR_EOF || result >= 0); | 105 return read_ok && (result == AVERROR_EOF || result >= 0); |
104 } | 106 } |
105 | 107 |
106 } // namespace media | 108 } // namespace media |
OLD | NEW |