OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 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 #include "media/base/video_frame_impl.h" | 5 #include "media/base/video_frame_impl.h" |
6 #include "media/filters/ffmpeg_common.h" | 6 #include "media/filters/ffmpeg_common.h" |
7 #include "media/filters/ffmpeg_demuxer.h" | 7 #include "media/filters/ffmpeg_demuxer.h" |
8 #include "media/filters/ffmpeg_video_decoder.h" | 8 #include "media/filters/ffmpeg_video_decoder.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 void FFmpegVideoDecoder::OnDecode(Buffer* buffer) { | 74 void FFmpegVideoDecoder::OnDecode(Buffer* buffer) { |
75 // Check for end of stream. | 75 // Check for end of stream. |
76 // TODO(scherkus): check for end of stream. | 76 // TODO(scherkus): check for end of stream. |
77 | 77 |
78 // Queue the incoming timestamp. | 78 // Queue the incoming timestamp. |
79 TimeTuple times; | 79 TimeTuple times; |
80 times.timestamp = buffer->GetTimestamp(); | 80 times.timestamp = buffer->GetTimestamp(); |
81 times.duration = buffer->GetDuration(); | 81 times.duration = buffer->GetDuration(); |
82 time_queue_.push(times); | 82 time_queue_.push(times); |
83 | 83 |
84 // Cast everything to FFmpeg types. | 84 // Create a packet for input data. |
85 const uint8_t* data_in = buffer->GetData(); | 85 // Due to FFmpeg API changes we no longer have const read-only pointers. |
86 const size_t size_in = buffer->GetDataSize(); | 86 AVPacket packet; |
| 87 av_init_packet(&packet); |
| 88 packet.data = const_cast<uint8*>(buffer->GetData()); |
| 89 packet.size = buffer->GetDataSize(); |
87 | 90 |
88 // We don't allocate AVFrame on the stack since different versions of FFmpeg | 91 // We don't allocate AVFrame on the stack since different versions of FFmpeg |
89 // may change the size of AVFrame, causing stack corruption. The solution is | 92 // may change the size of AVFrame, causing stack corruption. The solution is |
90 // to let FFmpeg allocate the structure via avcodec_alloc_frame(). | 93 // to let FFmpeg allocate the structure via avcodec_alloc_frame(). |
91 int decoded = 0; | 94 int decoded = 0; |
92 scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> yuv_frame(avcodec_alloc_frame()); | 95 scoped_ptr_malloc<AVFrame, ScopedPtrAVFree> yuv_frame(avcodec_alloc_frame()); |
93 int result = avcodec_decode_video(codec_context_, yuv_frame.get(), &decoded, | 96 int result = avcodec_decode_video2(codec_context_, yuv_frame.get(), &decoded, |
94 data_in, size_in); | 97 &packet); |
95 | 98 |
96 // Log the problem if we can't decode a video frame. | 99 // Log the problem if we can't decode a video frame. |
97 if (result < 0) { | 100 if (result < 0) { |
98 LOG(INFO) << "Error decoding a video frame with timestamp: " | 101 LOG(INFO) << "Error decoding a video frame with timestamp: " |
99 << buffer->GetTimestamp().InMicroseconds() << " us" | 102 << buffer->GetTimestamp().InMicroseconds() << " us" |
100 << " , duration: " | 103 << " , duration: " |
101 << buffer->GetDuration().InMicroseconds() << " us" | 104 << buffer->GetDuration().InMicroseconds() << " us" |
102 << " , packet size: " | 105 << " , packet size: " |
103 << buffer->GetDataSize() << " bytes"; | 106 << buffer->GetDataSize() << " bytes"; |
104 } | 107 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 185 } |
183 DCHECK(bytes_per_line <= source_stride && bytes_per_line <= dest_stride); | 186 DCHECK(bytes_per_line <= source_stride && bytes_per_line <= dest_stride); |
184 for (size_t i = 0; i < copy_lines; ++i) { | 187 for (size_t i = 0; i < copy_lines; ++i) { |
185 memcpy(dest, source, bytes_per_line); | 188 memcpy(dest, source, bytes_per_line); |
186 source += source_stride; | 189 source += source_stride; |
187 dest += dest_stride; | 190 dest += dest_stride; |
188 } | 191 } |
189 } | 192 } |
190 | 193 |
191 } // namespace | 194 } // namespace |
OLD | NEW |