|
Lines 1-216
Link Here
|
| 1 |
Some changes are identical to upstream: |
|
|
| 2 |
http://git.savannah.gnu.org/cgit/bino.git/commit/?id=bcba7045c99f |
| 3 |
http://git.savannah.gnu.org/cgit/bino.git/commit/?id=50b7109633fa |
| 4 |
http://git.savannah.gnu.org/cgit/bino.git/commit/?id=78023424d4cf |
| 5 |
|
| 6 |
--- src/media_object.cpp.orig 2013-01-27 21:04:48 UTC |
| 7 |
+++ src/media_object.cpp |
| 8 |
@@ -56,6 +56,23 @@ extern "C" |
| 9 |
|
| 10 |
#include "media_object.h" |
| 11 |
|
| 12 |
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(51, 42, 0) |
| 13 |
+#define AVPixelFormat PixelFormat |
| 14 |
+#define AV_PIX_FMT_BGRA PIX_FMT_BGRA |
| 15 |
+#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P |
| 16 |
+#define AV_PIX_FMT_YUV420P10 PIX_FMT_YUV420P10 |
| 17 |
+#define AV_PIX_FMT_YUV422P PIX_FMT_YUV422P |
| 18 |
+#define AV_PIX_FMT_YUV422P10 PIX_FMT_YUV422P10 |
| 19 |
+#define AV_PIX_FMT_YUV444P PIX_FMT_YUV444P |
| 20 |
+#define AV_PIX_FMT_YUV444P10 PIX_FMT_YUV444P10 |
| 21 |
+#define AV_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P |
| 22 |
+#define AV_PIX_FMT_YUVJ422P PIX_FMT_YUVJ422P |
| 23 |
+#define AV_PIX_FMT_YUVJ444P PIX_FMT_YUVJ444P |
| 24 |
+#endif |
| 25 |
+ |
| 26 |
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 25, 0) |
| 27 |
+#define AV_CODEC_ID_TEXT CODEC_ID_TEXT |
| 28 |
+#endif |
| 29 |
|
| 30 |
// The read thread. |
| 31 |
// This thread reads packets from the AVFormatContext and stores them in the |
| 32 |
@@ -150,7 +167,8 @@ public: |
| 33 |
// Hide the FFmpeg stuff so that their messy header files cannot cause problems |
| 34 |
// in other source files. |
| 35 |
|
| 36 |
-static const size_t audio_tmpbuf_size = (AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2; |
| 37 |
+static const size_t max_audio_frame_size = 19200; // 1 second of 48khz 32bit audio |
| 38 |
+static const size_t audio_tmpbuf_size = (max_audio_frame_size * 3) / 2; |
| 39 |
|
| 40 |
struct ffmpeg_stuff |
| 41 |
{ |
| 42 |
@@ -422,20 +440,20 @@ void media_object::set_video_frame_templ |
| 43 |
video_frame_template.value_range = video_frame::u8_full; |
| 44 |
video_frame_template.chroma_location = video_frame::center; |
| 45 |
if (!_always_convert_to_bgra32 |
| 46 |
- && (video_codec_ctx->pix_fmt == PIX_FMT_YUV444P |
| 47 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV444P10 |
| 48 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV422P |
| 49 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV422P10 |
| 50 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV420P |
| 51 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV420P10)) |
| 52 |
+ && (video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV444P |
| 53 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV444P10 |
| 54 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV422P |
| 55 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV422P10 |
| 56 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV420P |
| 57 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV420P10)) |
| 58 |
{ |
| 59 |
- if (video_codec_ctx->pix_fmt == PIX_FMT_YUV444P |
| 60 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV444P10) |
| 61 |
+ if (video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV444P |
| 62 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV444P10) |
| 63 |
{ |
| 64 |
video_frame_template.layout = video_frame::yuv444p; |
| 65 |
} |
| 66 |
- else if (video_codec_ctx->pix_fmt == PIX_FMT_YUV422P |
| 67 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV422P10) |
| 68 |
+ else if (video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV422P |
| 69 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV422P10) |
| 70 |
{ |
| 71 |
video_frame_template.layout = video_frame::yuv422p; |
| 72 |
} |
| 73 |
@@ -448,9 +466,9 @@ void media_object::set_video_frame_templ |
| 74 |
{ |
| 75 |
video_frame_template.color_space = video_frame::yuv709; |
| 76 |
} |
| 77 |
- if (video_codec_ctx->pix_fmt == PIX_FMT_YUV444P10 |
| 78 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV422P10 |
| 79 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUV420P10) |
| 80 |
+ if (video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV444P10 |
| 81 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV422P10 |
| 82 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUV420P10) |
| 83 |
{ |
| 84 |
video_frame_template.value_range = video_frame::u10_mpeg; |
| 85 |
if (video_codec_ctx->color_range == AVCOL_RANGE_JPEG) |
| 86 |
@@ -477,15 +495,15 @@ void media_object::set_video_frame_templ |
| 87 |
} |
| 88 |
} |
| 89 |
else if (!_always_convert_to_bgra32 |
| 90 |
- && (video_codec_ctx->pix_fmt == PIX_FMT_YUVJ444P |
| 91 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUVJ422P |
| 92 |
- || video_codec_ctx->pix_fmt == PIX_FMT_YUVJ420P)) |
| 93 |
+ && (video_codec_ctx->pix_fmt == AV_PIX_FMT_YUVJ444P |
| 94 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUVJ422P |
| 95 |
+ || video_codec_ctx->pix_fmt == AV_PIX_FMT_YUVJ420P)) |
| 96 |
{ |
| 97 |
- if (video_codec_ctx->pix_fmt == PIX_FMT_YUVJ444P) |
| 98 |
+ if (video_codec_ctx->pix_fmt == AV_PIX_FMT_YUVJ444P) |
| 99 |
{ |
| 100 |
video_frame_template.layout = video_frame::yuv444p; |
| 101 |
} |
| 102 |
- else if (video_codec_ctx->pix_fmt == PIX_FMT_YUVJ422P) |
| 103 |
+ else if (video_codec_ctx->pix_fmt == AV_PIX_FMT_YUVJ422P) |
| 104 |
{ |
| 105 |
video_frame_template.layout = video_frame::yuv422p; |
| 106 |
} |
| 107 |
@@ -879,7 +897,7 @@ void media_object::open(const std::strin |
| 108 |
{ |
| 109 |
_ffmpeg->format_ctx->streams[i]->discard = AVDISCARD_ALL; // ignore by default; user must activate streams |
| 110 |
AVCodecContext *codec_ctx = _ffmpeg->format_ctx->streams[i]->codec; |
| 111 |
- AVCodec *codec = (codec_ctx->codec_id == CODEC_ID_TEXT |
| 112 |
+ AVCodec *codec = (codec_ctx->codec_id == AV_CODEC_ID_TEXT |
| 113 |
? NULL : avcodec_find_decoder(codec_ctx->codec_id)); |
| 114 |
// XXX: Sometimes the reported width and height for a video stream change after avcodec_open(), |
| 115 |
// but the original values seem to be correct. This seems to happen mostly with 1920x1080 video |
| 116 |
@@ -899,8 +917,8 @@ void media_object::open(const std::strin |
| 117 |
if (codec_ctx->lowres || (codec && (codec->capabilities & CODEC_CAP_DR1))) |
| 118 |
codec_ctx->flags |= CODEC_FLAG_EMU_EDGE; |
| 119 |
} |
| 120 |
- // Find and open the codec. CODEC_ID_TEXT is a special case: it has no decoder since it is unencoded raw data. |
| 121 |
- if (codec_ctx->codec_id != CODEC_ID_TEXT && (!codec || (e = avcodec_open2(codec_ctx, codec, NULL)) < 0)) |
| 122 |
+ // Find and open the codec. AV_CODEC_ID_TEXT is a special case: it has no decoder since it is unencoded raw data. |
| 123 |
+ if (codec_ctx->codec_id != AV_CODEC_ID_TEXT && (!codec || (e = avcodec_open2(codec_ctx, codec, NULL)) < 0)) |
| 124 |
{ |
| 125 |
msg::wrn(_("%s stream %d: Cannot open %s: %s"), _url.c_str(), i, |
| 126 |
codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ? _("video codec") |
| 127 |
@@ -928,10 +946,15 @@ void media_object::open(const std::strin |
| 128 |
_ffmpeg->video_packets.push_back(AVPacket()); |
| 129 |
av_init_packet(&(_ffmpeg->video_packets[j])); |
| 130 |
_ffmpeg->video_decode_threads.push_back(video_decode_thread(_url, _ffmpeg, j)); |
| 131 |
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 28, 1) |
| 132 |
_ffmpeg->video_frames.push_back(avcodec_alloc_frame()); |
| 133 |
_ffmpeg->video_buffered_frames.push_back(avcodec_alloc_frame()); |
| 134 |
- enum PixelFormat frame_fmt = (_ffmpeg->video_frame_templates[j].layout == video_frame::bgra32 |
| 135 |
- ? PIX_FMT_BGRA : _ffmpeg->video_codec_ctxs[j]->pix_fmt); |
| 136 |
+#else |
| 137 |
+ _ffmpeg->video_frames.push_back(av_frame_alloc()); |
| 138 |
+ _ffmpeg->video_buffered_frames.push_back(av_frame_alloc()); |
| 139 |
+#endif |
| 140 |
+ enum AVPixelFormat frame_fmt = (_ffmpeg->video_frame_templates[j].layout == video_frame::bgra32 |
| 141 |
+ ? AV_PIX_FMT_BGRA : _ffmpeg->video_codec_ctxs[j]->pix_fmt); |
| 142 |
int frame_bufsize = (avpicture_get_size(frame_fmt, |
| 143 |
_ffmpeg->video_codec_ctxs[j]->width, _ffmpeg->video_codec_ctxs[j]->height)); |
| 144 |
_ffmpeg->video_buffers.push_back(static_cast<uint8_t *>(av_malloc(frame_bufsize))); |
| 145 |
@@ -944,20 +967,24 @@ void media_object::open(const std::strin |
| 146 |
if (_ffmpeg->video_frame_templates[j].layout == video_frame::bgra32) |
| 147 |
{ |
| 148 |
// Initialize things needed for software pixel format conversion |
| 149 |
- int sws_bufsize = avpicture_get_size(PIX_FMT_BGRA, |
| 150 |
+ int sws_bufsize = avpicture_get_size(AV_PIX_FMT_BGRA, |
| 151 |
_ffmpeg->video_codec_ctxs[j]->width, _ffmpeg->video_codec_ctxs[j]->height); |
| 152 |
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 28, 1) |
| 153 |
_ffmpeg->video_sws_frames.push_back(avcodec_alloc_frame()); |
| 154 |
+#else |
| 155 |
+ _ffmpeg->video_sws_frames.push_back(av_frame_alloc()); |
| 156 |
+#endif |
| 157 |
_ffmpeg->video_sws_buffers.push_back(static_cast<uint8_t *>(av_malloc(sws_bufsize))); |
| 158 |
if (!_ffmpeg->video_sws_frames[j] || !_ffmpeg->video_sws_buffers[j]) |
| 159 |
{ |
| 160 |
throw exc(HERE + ": " + strerror(ENOMEM)); |
| 161 |
} |
| 162 |
avpicture_fill(reinterpret_cast<AVPicture *>(_ffmpeg->video_sws_frames[j]), _ffmpeg->video_sws_buffers[j], |
| 163 |
- PIX_FMT_BGRA, _ffmpeg->video_codec_ctxs[j]->width, _ffmpeg->video_codec_ctxs[j]->height); |
| 164 |
+ AV_PIX_FMT_BGRA, _ffmpeg->video_codec_ctxs[j]->width, _ffmpeg->video_codec_ctxs[j]->height); |
| 165 |
// Call sws_getCachedContext(NULL, ...) instead of sws_getContext(...) just to avoid a deprecation warning. |
| 166 |
_ffmpeg->video_sws_ctxs.push_back(sws_getCachedContext(NULL, |
| 167 |
_ffmpeg->video_codec_ctxs[j]->width, _ffmpeg->video_codec_ctxs[j]->height, _ffmpeg->video_codec_ctxs[j]->pix_fmt, |
| 168 |
- _ffmpeg->video_codec_ctxs[j]->width, _ffmpeg->video_codec_ctxs[j]->height, PIX_FMT_BGRA, |
| 169 |
+ _ffmpeg->video_codec_ctxs[j]->width, _ffmpeg->video_codec_ctxs[j]->height, AV_PIX_FMT_BGRA, |
| 170 |
SWS_POINT, NULL, NULL, NULL)); |
| 171 |
if (!_ffmpeg->video_sws_ctxs[j]) |
| 172 |
{ |
| 173 |
@@ -1000,9 +1027,9 @@ void media_object::open(const std::strin |
| 174 |
int j = _ffmpeg->subtitle_streams.size() - 1; |
| 175 |
msg::dbg(_url + " stream " + str::from(i) + " is subtitle stream " + str::from(j) + "."); |
| 176 |
_ffmpeg->subtitle_codec_ctxs.push_back(codec_ctx); |
| 177 |
- // CODEC_ID_TEXT does not have any decoder; it is just UTF-8 text in the packet data. |
| 178 |
+ // AV_CODEC_ID_TEXT does not have any decoder; it is just UTF-8 text in the packet data. |
| 179 |
_ffmpeg->subtitle_codecs.push_back( |
| 180 |
- _ffmpeg->subtitle_codec_ctxs[j]->codec_id == CODEC_ID_TEXT ? NULL : codec); |
| 181 |
+ _ffmpeg->subtitle_codec_ctxs[j]->codec_id == AV_CODEC_ID_TEXT ? NULL : codec); |
| 182 |
_ffmpeg->subtitle_box_templates.push_back(subtitle_box()); |
| 183 |
set_subtitle_box_template(j); |
| 184 |
_ffmpeg->subtitle_decode_threads.push_back(subtitle_decode_thread(_url, _ffmpeg, j)); |
| 185 |
@@ -1505,7 +1532,7 @@ read_frame: |
| 186 |
// We need to buffer the data because FFmpeg will clubber it when decoding the next frame. |
| 187 |
av_picture_copy(reinterpret_cast<AVPicture *>(_ffmpeg->video_buffered_frames[_video_stream]), |
| 188 |
reinterpret_cast<AVPicture *>(_ffmpeg->video_frames[_video_stream]), |
| 189 |
- static_cast<enum PixelFormat>(_ffmpeg->video_codec_ctxs[_video_stream]->pix_fmt), |
| 190 |
+ static_cast<enum AVPixelFormat>(_ffmpeg->video_codec_ctxs[_video_stream]->pix_fmt), |
| 191 |
_ffmpeg->video_codec_ctxs[_video_stream]->width, |
| 192 |
_ffmpeg->video_codec_ctxs[_video_stream]->height); |
| 193 |
src_frame = _ffmpeg->video_buffered_frames[_video_stream]; |
| 194 |
@@ -1776,8 +1803,8 @@ void subtitle_decode_thread::run() |
| 195 |
int got_subtitle; |
| 196 |
tmppacket = packet; |
| 197 |
|
| 198 |
- // CODEC_ID_TEXT does not have any decoder; it is just UTF-8 text in the packet data. |
| 199 |
- if (_ffmpeg->subtitle_codec_ctxs[_subtitle_stream]->codec_id == CODEC_ID_TEXT) |
| 200 |
+ // AV_CODEC_ID_TEXT does not have any decoder; it is just UTF-8 text in the packet data. |
| 201 |
+ if (_ffmpeg->subtitle_codec_ctxs[_subtitle_stream]->codec_id == AV_CODEC_ID_TEXT) |
| 202 |
{ |
| 203 |
int64_t duration = packet.convergence_duration * 1000000 |
| 204 |
* _ffmpeg->format_ctx->streams[_ffmpeg->subtitle_streams[_subtitle_stream]]->time_base.num |
| 205 |
@@ -1937,9 +1964,9 @@ void media_object::seek(int64_t dest_pos |
| 206 |
} |
| 207 |
for (size_t i = 0; i < _ffmpeg->subtitle_streams.size(); i++) |
| 208 |
{ |
| 209 |
- if (_ffmpeg->format_ctx->streams[_ffmpeg->subtitle_streams[i]]->codec->codec_id != CODEC_ID_TEXT) |
| 210 |
+ if (_ffmpeg->format_ctx->streams[_ffmpeg->subtitle_streams[i]]->codec->codec_id != AV_CODEC_ID_TEXT) |
| 211 |
{ |
| 212 |
- // CODEC_ID_TEXT has no decoder, so we cannot flush its buffers |
| 213 |
+ // AV_CODEC_ID_TEXT has no decoder, so we cannot flush its buffers |
| 214 |
avcodec_flush_buffers(_ffmpeg->format_ctx->streams[_ffmpeg->subtitle_streams[i]]->codec); |
| 215 |
} |
| 216 |
_ffmpeg->subtitle_box_buffers[i].clear(); |