| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/filters/bitstream_converter.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "media/ffmpeg/ffmpeg_common.h" | |
| 9 | |
| 10 namespace media { | |
| 11 | |
| 12 bool IdentityBitstreamConverter::Initialize() { | |
| 13 return true; | |
| 14 } | |
| 15 | |
| 16 bool IdentityBitstreamConverter::ConvertPacket(AVPacket* packet) { | |
| 17 return true; | |
| 18 } | |
| 19 | |
| 20 FFmpegBitstreamConverter::FFmpegBitstreamConverter( | |
| 21 const std::string& filter_name, | |
| 22 AVCodecContext* stream_context) | |
| 23 : filter_name_(filter_name), | |
| 24 stream_filter_(NULL), | |
| 25 stream_context_(stream_context) { | |
| 26 CHECK(stream_context_); | |
| 27 } | |
| 28 | |
| 29 FFmpegBitstreamConverter::~FFmpegBitstreamConverter() { | |
| 30 if (stream_filter_) { | |
| 31 av_bitstream_filter_close(stream_filter_); | |
| 32 stream_filter_ = NULL; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 bool FFmpegBitstreamConverter::Initialize() { | |
| 37 stream_filter_ = av_bitstream_filter_init(filter_name_.c_str()); | |
| 38 return stream_filter_ != NULL; | |
| 39 } | |
| 40 | |
| 41 bool FFmpegBitstreamConverter::ConvertPacket(AVPacket* packet) { | |
| 42 CHECK(packet); | |
| 43 | |
| 44 if (!stream_filter_) { | |
| 45 LOG(ERROR) << "Converter improperly initialized."; | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 uint8_t* converted_data = NULL; | |
| 50 int converted_size = 0; | |
| 51 | |
| 52 if (av_bitstream_filter_filter(stream_filter_, stream_context_, NULL, | |
| 53 &converted_data, &converted_size, | |
| 54 packet->data, packet->size, | |
| 55 packet->flags & AV_PKT_FLAG_KEY) < 0) { | |
| 56 return false; | |
| 57 } | |
| 58 | |
| 59 // av_bitstream_filter_filter() does not always allocate a new packet. | |
| 60 // If a new packet was allocated, then we need to modify the | |
| 61 // |packet| to point to the new data, releasing its current payload | |
| 62 // if it has the authoritative reference. | |
| 63 // | |
| 64 // TODO(ajwong): We're relying on the implementation behavior of | |
| 65 // av_free_packet() and the meaning of the |destruct| field in | |
| 66 // AVPacket. Try to find a cleaner way to do this. | |
| 67 if (converted_data != packet->data) { | |
| 68 av_free_packet(packet); | |
| 69 packet->data = converted_data; | |
| 70 packet->size = converted_size; | |
| 71 packet->destruct = av_destruct_packet; | |
| 72 } | |
| 73 | |
| 74 return true; | |
| 75 } | |
| 76 | |
| 77 } // namespace media | |
| OLD | NEW |