History log of /haiku/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp
Revision Date Author Comments
# aa977a02 05-Apr-2024 Augustin Cavalier <waddlesplash@gmail.com>

ffmpeg: Fix fCodecContext initialization and usage.

* Don't allocate a context up front if we're
just going to free it anyway.

* Actually set the various flags originally set
in the constructor in the place where the context
is actually allocated.

* Remove now-duplicate thread_count assignment.


# 1f09e28c 02-Apr-2024 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: enable multi-threaded decoding

Fixes #18874.

Change-Id: I24c74080fcc8280796af64624e0cdbf96cd57dc7
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7586
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# b0674032 30-Mar-2024 PulkoMandy <pulkomandy@pulkomandy.tk>

AVCodecDecoder: remove legacy ffmpeg support

Change-Id: I103ab2d7063dca33f2ef9c04202dd1699f871196
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7564
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>


# 3281146c 30-Mar-2024 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: implement equivalent of avcodec_guess_frame_rate

The frame rate in the codec context isn't always a frame frate in the
video sense. It may be a smaller time unit used as a base for the frame
presentation timestamps.

I did not initially notice this because we set it to a default value
from the AVFormat passed input encoded_video format, but it is erased
after reading the first frame.

Fixes #18797.

Change-Id: I6157ae9942f6d5ca32aad7bac012df0822659a21
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7563
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>


# 43f35014 30-Mar-2024 PulkoMandy <pulkomandy@pulkomandy.tk>

AVCodecDecoder: fix build with tracing enabled

Change-Id: Id1f79faf218a589d68c81258e4a88ee2d3b001be
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7562
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 45bd581b 14-Mar-2024 Augustin Cavalier <waddlesplash@gmail.com>

media/ffmpeg: Pass most packet metadata to decoder.

While AVPacket itself contains other fields, the
important ones are all static, and fit in 64 bytes.
So we can put them into the chunk media header directly
and then grab them again in AVCodecDecoder.

With that passed through, we can then use the
best_effort_timestamp, as it's more likely to be
correct.

Change-Id: Ied82137694f1307d4dcb177f3f9a7cb6b798461a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7525
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 1774dd5e 29-Dec-2023 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: channels and channel_layout are deprecated

Use ch_layout instead

Change-Id: I6a07870eae42836d3fd993c253613bc0f33b1598
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7252
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# 0199d1f3 29-Dec-2023 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: remove interlaced_frame

Change-Id: I870bea36c6180e46ae3d63fe407126606bdda3c1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7254
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# c020b083 29-Dec-2023 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: remove unused and broken video framerate computation

ffmpeg already provides us with a framerate if it is known at the stream
level. If it is not known at this level, the framerate may not be fixed
througout the video, and so the best thing to do is to leave the media
kit field_rate unset, and let applications handle frames according to
their presentation timestamps as they come (this is what we had been
doing anyway, the code to output the framerate to the media kit had been
commented out for a long time and the computed value was not used)

Since ffmpeg removed the ticks_per_frame field [1], the code would not
compile anymore with later ffmpeg versions.

[1] https: //patchwork.ffmpeg.org/project/ffmpeg/patch/20230507133255.20881-12-anton@khirnov.net/

Change-Id: Icc0988c507965883a1570e46f904ebf235fb71bc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7247
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# bda0b2b0 29-Dec-2023 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: remove AVCODEC_FLAG/CAP_TRUNCATED

https: //ffmpeg.org/pipermail/ffmpeg-devel/2021-September/285257.html
Change-Id: I61c306a9f040378afbe643a1ab3869cff60c2690
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7253
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 9bf436a2 29-Dec-2023 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: av_init_packet is deprecated

https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=3189

Change-Id: I5ac25141ce76b2f7737e2f1b7ce5c8eac4a90082
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7249
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# e691cf1e 14-Dec-2023 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: avcodec_free_context seems to also free extradata

* context->extradata seems to be set to fExtraData or fInputFormat.MetaData().
Both are managed by us, so set context->extradata to NULL before freeing.
* avcodec_close() shouldn't use according to the documentation:
"Use avcodec_free_context() to destroy a codec context (either open or closed).
Opening and closing a codec context multiple times is not supported anymore – use multiple codec contexts instead."
* fix #18713

Change-Id: I820deefcffea52a39fcb7587153d40dc03c85024
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7208
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 1b887085 14-Nov-2023 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: fix leak when decoding audio frames

removing the memset in _DecodeSomeAudioFramesIntoEmptyDecodedDataBuffer fixes #18654
also free correctly resources in AVCodecDecoder destructor.

Change-Id: I2d6de6b50ba6767f669eb765dad96d28d43100fb
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7108
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 9858be4f 09-Aug-2023 PulkoMandy <pulkomandy@pulkomandy.tk>

ffmpeg: remove usage of deprecated method avcodec_decode_audio4

Use avcodec_send_packet and avcodec_receive_frame as recommended in
ffmpeg documentation.

Change-Id: Ib9dc343a9f5cfbc50192158934e5e80c09a37fab
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6803
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# 425ac1b6 20-Jun-2023 Alexander von Gluck IV <kallisti5@unixzen.com>

refactor: Swap %Ld for %lld in all format usages

* %Ld is an undocumented alias for %lld in glibc.
* muslc doesn't implement it for this reason.
* While we will likely never drop %Ld support,
lets clean house and set a better example.

Change-Id: Id46dad3104abae483e80cc5c05d1464d3ecd8030
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6636
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 7f7f9f1d 13-Dec-2020 Máximo Castañeda <antiswen@yahoo.es>

ffmpeg decoder: return last chunk of audio

Change-Id: I712e5959f066e65471777e6724637aac7a17d07c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3510
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 92290d9b 02-May-2020 Adrien Destugues <pulkomandy@pulkomandy.tk>

ffmpeg: return B_LAST_BUFFER_ERROR when decoding completes.

Fixes #13622.
Fixes #14773.
Fixes #15220.

Change-Id: I2c20b421d25b450714209f4f4f4205d61145e615
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2551
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# f9c74ffa 29-Jan-2019 Murai Takashi <tmurai01@gmail.com>

add-ons/media/plugins/ffmpeg: Fix PVS 2355

Fix memory leak when realloc() fails.

Change-Id: I12b57fecbd7f9645f15afb9d0f9a6db937a5ec09
Reviewed-on: https://review.haiku-os.org/c/1014
Reviewed-by: Barrett17 <b.vitruvio@gmail.com>


# 5490645d 04-Dec-2018 Adrien Destugues <pulkomandy@pulkomandy.tk>

ffmpeg: Undo changes to frame time computation

I was misled by ffmpeg docs, the timestamp is indeed in microseconds
already at this point.


# 4c8208af 08-Nov-2018 Adrien Destugues <pulkomandy@pulkomandy.tk>

ffmpeg: fix crash at end of video stream

Mixing new and old style decoding APIs won't work. And we were still
using the old API for managing the end of videos.

Change-Id: Ic194ab98721455658ecefde4f951c3f1e43ae1be
Reviewed-on: https://review.haiku-os.org/679
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 5e14319a 04-Nov-2018 Adrien Destugues <pulkomandy@pulkomandy.tk>

ffmpeg: use new producer/consumer API for video decoding

This API allows us to send whole packets no matter how the video is
formatted, and get frames out as they are ready (sometimes multiple
frames per packets, which did not work well with the previous API).

Change-Id: I0bd7d4706e330bb11d87cb41e93cfc6995b4b3a5
Reviewed-on: https://review.haiku-os.org/665
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 9e2c056c 04-Nov-2018 Adrien Destugues <pulkomandy@pulkomandy.tk>

ffmpeg: fix timestamp tracing

Use ffmpeg functions to format the timestamps.

Change-Id: Idd51feb22fc6c5a70e177604eb995ae2d8601cd4
Reviewed-on: https://review.haiku-os.org/663
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# e5bb653b 23-Sep-2018 Augustin Cavalier <waddlesplash@gmail.com>

add-ons/media/ffmpeg: Rework usage of AVPicture in AVCodecDecoder.

It has been deprecated since FFmpeg ~3.0, and is internally implemented
using these functions now, so this should largely be a no-op change.

AVCodecEncoder still uses it.


# fee62e6a 27-Aug-2018 JackBurton79 <stefano.ceccherini@gmail.com>

ffmpeg media decoder: revert latest changes to the AVCodecDecoder destructor.
Let's see if it fixes #14394.

Change-Id: Iba3a77197703b43f7c5e29292940b3a9018b4585


# de9e43cd 24-Aug-2018 JackBurton79 <stefano.ceccherini@gmail.com>

ffmpeg media decoder: Fix double free() (and possibly #14394.
Don't call avcodec_close() and then avcodec_free_context().
The latter replaces the former.

http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2ef6dab0a79a9852a92ed80b07f9e32a37530d9e

Change-Id: I346dc8da20a274bcfd901b4a67e612f0f38323b0


# 1d404e45 14-Aug-2018 JackBurton79 <stefano.ceccherini@gmail.com>

ffmpeg plugin: use avformat/codec_free_context() where applicable


# 3bd0b6ec 11-Aug-2018 Adrien Destugues <pulkomandy@pulkomandy.tk>

ffmpeg: do not compute a duration for streaming streams.

Streaming means the stream is endless, so don't compute a duration.

ffmpeg computes an estimation using what it thinks is the file size, but
is instead some internal buffer size from BAdapterIO.

Fixes second part of #14326.


# e302fe32 04-Aug-2018 Barrett17 <b.vitruvio@gmail.com>

AVCodecDecoder: Rename fContext to fCodecContext


# 334b8f3f 03-Aug-2018 Barrett17 <b.vitruvio@gmail.com>

ffmpeg: Remove obsolete code


# d1c51097 02-Jul-2018 Augustin Cavalier <waddlesplash@gmail.com>

Upgrade FFmpeg to 4.0.1 across the board (including GCC2.)

This was accomplished by adding some pretty nasty hacks to the FFmpeg recipe
so that we can compile it for the GCC2 ABI using GCC7. This works because
GCC's C ABI has not changed between GCC2 and GCC7.

As a consequence of this, pretty much all the longstanding issues of the
ancient-and-still-miscompiled FFmpeg 0.10 are now completely gone.

Fixes #5080, #8461, #12696, #12436, #13981 #13410, #13337.
Closes (possibly fixed earlier) #8605, #8511, #6984.
Probably fixes (couldn't test) #13989, #11974.


# 2b1481f0 01-Dec-2017 Augustin Cavalier <waddlesplash@gmail.com>

Fix a few more miscellaneous (harmless) Clang warnings.


# 0b6c89fb 22-Jul-2017 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: implement deinterlace feature for ffmpeg 3.x.

* Use the yadif filter.
* Fixes #12731.


# d4e70d10 20-Jul-2017 Jerome Duval <jerome.duval@gmail.com>

ffmpeg: output B_RGB32 when using libswscale.


# 99edf9d9 08-Apr-2017 Adrien Destugues <pulkomandy@pulkomandy.tk>

Remove another overzealous assert.

Fixes playing "swinging.mp4" from our demo video package.


# 7af63063 31-Oct-2016 Jérôme Duval <jerome.duval@gmail.com>

media/ffmpeg: skips libswr, and interleaves samples for planar audio.

* workaround for #12720.


# d1175e07 05-Jul-2016 Alexander von Gluck IV <kallisti5@unixzen.com>

media/ffmpeg: Fix a few minor x86_64 warnings


# 269796df 21-Feb-2016 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: add TODO on reimplementing deinterlace for ffmpeg 3.


# f97f2394 19-Feb-2016 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: update build with version 3.0.

* untested.


# da455572 14-Feb-2016 Adrien Destugues <pulkomandy@gmail.com>

AVCodecDecoder: fix timing problems

A combination of two problems made things go wrong with the timestamp of
decoded audio.

1) The output buffer size is too small to hold the complete input.
swresample handles this by buffering the input for use the next time it
is called, however repeatedly doing this results in lots of buffering,
and our way to compute the output timestamp from the input does not take
it into account so it does weird things. Moreover, we would need to
empty the buffer by calling swr_convert with NULL input in that case.

Fix: make sure to not feed more data to swr_convert than it can output
in our buffer. This way, no buffering occurs, only the matrixing
conversion.

2) When using planar audio, the "frame size" is a bit different. Instead
of adding sample size * channel count to 1 pointer, we need to add
sample size * 1 to each channel buffer.

Fix: add the "fInputFrameSize" which takes this into account, instead of
misusing fOutputFrameSize for the input.

Fixes #12460.


# 2c499439 31-Dec-2015 Adrien Destugues <pulkomandy@pulkomandy.tk>

Use the existing ffmpeg function to decide if a format is planar.


# 8113bbfe 28-Dec-2015 Jessica Hamilton <jessica.l.hamilton@gmail.com>

ffmpeg addon: only use swresample for planar audio.

Fixes #12547.


# 3c5c6990 21-Dec-2015 Adrien Destugues <pulkomandy@gmail.com>

Really fix swr_convert usage for gcc2.


# 9dd9b454 19-Dec-2015 Adrien Destugues <pulkomandy@gmail.com>

Use swresample to rematrix audio channels, try 2

This code is closer to what we used before for gcc2, and should not
crash there anymore. I could not get exactly the same code to work, but
reduced the difference to a single statement (which makes gcc2 work and
breaks gcc4). This is protected under a guard with appropriate ffmpeg
version test.

This code works for both gcc2 and gcc4 (tested with mp3 and aac files as
well as youtube videos). It still gets the timestamps wrong with ffmpeg
2.4, but I'll try to solve that another time.


# 8a822b7c 17-Dec-2015 Augustin Cavalier <waddlesplash@gmail.com>

Revert "AVCodecDecoder: use swresample to interleave audio channels."

Commit 856cc59e58bb83de4a69daa680748ba9b52592d8 didn't really "fix"
anything; it just broke audio pretty much everywhere but YouTube,
and there videos play at 2x speed so it wasn't really worth it.

Stopgap solution for #12509.


# 946163e3 20-Nov-2015 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: fix x86_64 build.


# 856cc59e 18-Nov-2015 Adrien Destugues <pulkomandy@gmail.com>

AVCodecDecoder: use swresample to interleave audio channels.

Some codecs will always output audio in planar mode no matter what we
request. This is the case for example with AAC used for youtube. We now
use swresample to convert from planar to packed format.

Note that since swresample does its own buffering, we could probably do
away with some of the code that handled buffering before, making the
audio pipeline simpler and faster.

Fixes audio in youtube, but now the video plays at 2x speed. It seems
something is wrong with the timestamps. Possible things to investigate:
* why do we use the packet dts instead of the pts from the frames anyway?
* the pts and pkt_dts are in "stream time_base units". We seem to assume
microseconds for audio but this is probably not the case. Or did I
miss where the conversion is done?


# 894640da 14-Nov-2015 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg: recognize planar audio and request packed instead

* Our media kit is designed to work with packed audio: which means the
samples from different channels are interleaved in a single stream
* Old ffmpeg versions also used this, but they now switched to the
planar format, where each channel is stored separately.
* Fortunately, we can request ffmpeg to use the packed format. We
actually already tried to do that, but the API for requesting a sample
format has also changed.
* Finally, we didn't recognize the packed format reported by the codecs,
which in some cases could lead to 16/32 bit mismatches on top of the
planar/packed mixup.

Fixes audio with ffmpeg 2.8 (ticket #12460)


# 278af8e2 30-Aug-2015 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg: check against correct version constants.

54.23.x is ffmpeg 0.11, which still has "CodecID" (and x>0).


# f618c89e 30-Aug-2015 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg: detect the library version the right way.

* Fixes the build by detecting the library version using the provided
constants, instead of guessing from the compiler version.


# 9e5c6946 30-Aug-2015 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg plugin: remove more deprecated functions.

These were all deprecated between releases 0.6 and 0.10 of ffmpeg,
except for one change (renaming of CodecID to AVCodecID) which we can
work around with a typedef. The deprecated functions were still
available in 0.11, but were removed later on after several years of
deprecation.

This makes it possible to build our plugin with any ffmpeg version
between 0.10 and 2.7, so we can now experiment with updating to 2.7 at
least for the gcc4 builds.


# 1148ea73 10-Dec-2014 Adrien Destugues <pulkomandy@gmail.com>

AVCodecDecoder: remove annoying assert.

According to Colin this is not supposed to happen, but it does. Since
the affected video otherwise decodes just fine, I think it is safe to
disable the assert and not annoy our users.

Fixes #11409.


# ff68ae98 09-Dec-2014 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg: disable runtime frame rate changes support.

This change was introduced by Colin for DVB-T support, however it also
breaks the timing of several MP4 files. The code is incomplete and
computes slightly to very wrong frame rates (one video plays about twice
as fast as needed, another one attempts to play at 30000 FPS).

I suspect similar problems would be found when changing the frame rate
in DVB-T streams in the same way, so I'm disabling this code for now
until a correct solution is found or we manage to use a newer version of
ffmpeg (where there is an actual framerate field in the format and it
doesn't need to be derived from the time_base anymore).

This restores the previous behavior of computing the framerate at the
AVFormatReader level, that is, once per stream, rather than once per
frame. At the stream level we have enough data to compute an "average"
frame rate, and there is also an "r_frame_rate" (real frame rate) which
may be usable for this. Not having working DVB-T hardware to experiment
with that yet, I'll leave it to others.

Fixes #11283 and the last remaining problem in #4512.


# 4ff7c2cc 25-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Small refactoring in audio path.

- Lazy initializing the fDecodedData variable fits best in
_ResetRawDecodedAudio() as fRawDecodedAudio is all about managing properties
of fDecodedData. So fDecodedData having some memory allocated is seen as a
property here.

- Updated documentation accordingly

- No functional change intended.


# fe1eb3c1 25-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix performance regression on video path.

- For best performance the color conversion function expects a memory location
aligned to 32 bytes. Without that alignment the color conversion function
falls back to a slower conversion path. This fix was measured via
DO_PROFILING and tested with various 1080p video files.


# 1c5f1830 25-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix correct decoding of first video frame.

- The first decoded video frame was always zero bytes large, due to passing the
wrong linesize to the color conversion function. The field containing the
right linesize (fHeader.u.raw_video.bytes_per_row) simply wasn't initialized
yet. Fix it by updating fHeader first before applying deinterlacing and color
converting to the decoded video frame.
Tested with mpeg2_decoder_test where the first picture now isn't empty
(black) anymore.


# f7f67022 24-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement audio input buffer padding.

- Padding is required by FFMPEG for correct operation of all audio decoders.
FFMPEG performs some speed optimizations under the hood that may lead to
reading over the end of the chunk buffer wouldn't there have been padding
applied.

- Resolve TODOs by unifying fVideoChunkBuffer and fChunkBuffer back into
fChunkBuffer because audio path is responsible for freeing fChunkBuffer now.
Resolved TODOs apply to the replacing fVideoChunkBuffer variable by
fChunkBuffer, rename some methods by removing the "Video" part, collapse two
methods into one (_LoadNextChunkIfNeededAndAssignStartTime()).
No functional change intended.

- Enhance "logging stream to file" functionality to write to distinct logging
files for audio and video. Before this commit one could only log video
streams. But with unifying the _LoadNextChunkIfNeededAndAssignStartTime()
audio streams gained the logging functionality for free. But now audio and
video streams would be written in the same log file when watching a media
file containing both audio and video. This is prevented by the distinct
logging mentioned above.

- Update documentation accordingly.


# 3c68ae7c 24-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out copying of audio format properties.

- Main reasons for this refactoring of negotiation steps are to increase
readability and to be on par with the video path.

- Rearrange some negotiation steps in video path to be on par with audio path.

- Add documentation for the new method and update existing documentation
accordingly.

- No functional change intended.


# ffb0f5db 23-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Automatic detection of audio decoding parameters.

- Kudos to Marcus Overhagen for laying out the general idea of automatic
detection by sharing some of his dvb code examples with me.
- Automatically detect the audio frame rate, channel count and sample format.
- Share audio sample format conversion code between AVFormatReader and
AVCodecDecoder.
- Tested with several video and audio files via MediaPlayer.
- Tested also with test case mp3_decoder_test -after- removing the hard coded
audio decoding parameters. Although the test shows that auto detection is
working (via stepping through the auto detection code path) the complete test
is still failing, due to missing implementation of incomplete audio frame
decoding.
- Add and update the documentation accordingly.


# 1a963de4 23-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out audio frames chunk decoding.

- Main purpose is to prepare auto detection of audio frame properties for
media formats that encode those properties in the frames themself (e.g. MP3)
instead of in the container format (e.g. WMA).
The main difference between akin named methods _DecodeNextAudioFrame() and
_DecodeNextAudioFrameChunk() is that the former method deals with providing
the exact number of audio frames expected by the caller of
BMediaDecoder::Decode() and the latter deals with decoding any number of
audio frames at all.

- New documentation added and existing documentationupdated accordingly.

- No functional change intended.


# 3c6f9c10 22-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fill out more media header fields in audio path.

- Some small refactoring when resetting fRawDecodedAudio. Instead of letting
FFMPEG reset fRawDecodedAudio we do it manually to preserve the allocated
memory in fRawDecodedAudio->opaque (otherwise FFMPEG's
avcodec_get_frame_defaults() would NULLify the opaque pointer without
releasing the allocated memory.

- Keep track of the total size of fDecodedData in fRawDecodedAudio->linesize[0]
instead of relying on calculating it every time it is needed. This makes the
code more comprehensible.


# 1b8bbb50 22-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out checking of invalid conditions in audio path.

- Main reason for this refactoring is to increase readability and thus make
audio decode path more comprehensible.

- Added documentation for the new method accordingly.

- Small change in calculating the decoded data size to clear when error occurs
during decoding. This way it is more readable and more consistent with
calculations of decoded data size on other locations.

- No functional change intended.


# ca5c686d 22-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out moving audio frames from buffer.

- Main reason for this refactoring is to increase readability and thus make the
audio decode path more comprehensible.

- Added documentation for the new method accordingly.

- No functional change intended.


# 7dc2773c 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out chunk loading in audio path.

- Main reasons are to increase readability of audio path and to demonstrate
that chunk loading in audio and video path is the same code that can be
focused in one method (instead of two at the moment). Added a TODO for
collapsing both methods into one and the conditions that must hold true to
do so (just in case I'll be hitted by a bus and someone else has to proceed).
Collapsing is scheduled for a later commit.

- Added documentation for the new method accordingly.

- Make use of full line length in comments of
_LoadNextVideoChunkIfNeededAndAssignStartTime().

- No functional change intended.


# 463f3402 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out actual audio decoding part.

- Main reason for this refactoring is to increase readability and thus make the
audio decode path more comprehensible.

- Added documentation for the new method accordingly.

- Small refactoring for detecting when to update fRawDecodedAudio's properties.
This is a preparation step for factoring out the flushing of the
fDecodedDataBuffer in a later commit.

- No functional change intended.


# 815d18fb 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor start time handling in audio path.

- FFMPEG handles the relationship of start time between encoded and decoded
audio data now by using the fTempPacket->dts and the
fDecodedDataBuffer->pkt_dts fields. We still have to manually keep track of
start times for consecutive audio frames though to support returning a number
of audio frames that may assembled of partial AVFrames.

- The start time of the very first audio frame data packet returned by Decode()
is now correctly calculated based on GetNextChunk() start times instead of
being always zero.

- Introduce fRawDecodedAudio that serves as a container to store properties of
the audio frames stored in fDecodedData. This prepares the population of the
fHeader structure with audio frame properties needed to allow clients of
BMediaDecoder::Decode() detect audio format changes in a later commit.

- Remove fStartTime as it is superflous now.


# 7f485803 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Print debug output for audio frames, too

- Also change what is printed for video frames. Currently both
debug_fframe_[audio|video] are used in AVCodecDecoder only and thus are
streamlined for their usage there. For example we print the AVFrame.pkt_dts
field instead of the AVFrame.pkt field because the later one is never touched
by AVCodecDecoders usage of the FFMPEG library.
Note: AVFrame.pkt being never touched means that it always contains the value
AV_NOPTS_VALUE making it less useful for debug purposes.


# b82ef8bc 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor scope of fTempPacket in audio path.

- There are two main reasons for this refactoring:
1. Prepare using FFMPEGs functionality of audio frame start time assignment
(instead of rolling it ourself) like already done for the video path
(see _LoadNextVideoChunkIfNeededAndAssignStartTime() for reference).
2. Get rid of fChunkBufferOffset (this is a minor reason though).

- Untangle some of the conditional checks to increase readability.

- No functional change intended.


# 3bca6098 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Rename some variables in audio path.

- Make the difference between fDecodedData and fDecodedDataBuffer more clear.

- No functional change intended.


# 85371234 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor audio decoding method into two.

- First method is solely responsible to fill the audio output buffer with
already decoded audio frames.
Second method is solely responsible for decoding the encoded audio data and
put it in the decoded audio output buffer for further processing with the
first method.
This prepares auto detection of audio frame properties for audio formats
where the properties are contained within the encoded audio frame (e.g. MP3),
instead within the audio container format (e.g. WMA). Implementing auto
detection is scheduled for a later commit though.

- Added documentation accordingly.

- No functional change intended.


# 54b392b4 19-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Some cleanups.

- Use name that correctly reflects the return value of avcodec_decode_video2().
- Make DO_PROFILING code path of AVCodecDecoder compile again.
- No functional change intended.


# 75bd62e8 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix playing video files.

- This should fix the bug where video files that played well before the recent
changes to the FFMPEG Plugin didn't play anymore. Now we apply the essential
video container properties (that were passed by with Setup()) to the
AVCodecContext. Some video formats simply store those properties in the
container only (e.g. AVI, WMV) and not in the video frames itself
(e.g. MPEG2).
Tested with several files from samples.ffmpeg.org and from the FATE suite of
FFMPEG.


# ed9de7df 10-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix video start_time handling

- I misinterpreted the semantics of reordered_opaque. I thought it would
establish the correct relationship between the start_time returned by
GetNextChunk() and the next video frame successfully decoded. But for this
to work reordered_opaque expects to be filled with presentation time stamps.
A series of presentation time stamps may be jumping back in time due to the
presence of B-frames. The decoded frame presentation time stamps series would
then be ordered in a monotonically increased way.
But actually GetNextChunk() always returns monotonically increasing start
times. Mapping this behaviour to FFMPEG's expectations means labeling those
start times as decoding time stamps (dts). Though for those start times to be
related to the correct decoded video frames you have to assign the start time
with the AVPacket containing the data to be decoded.

- This commit finally makes DVB video playback working for me with the TV app.
Though no audio yet.

- The documentation was updated accordingly.


# b77f1724 07-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Calculate media_header.size_used field

- This field is needed by the dvb.media_addon to detect a format change so
fill it with the correct value.
- Updated documentation accordingly to reflect reordered function calls and new
assumptions based on the function call ordering.


# 6063c02e 05-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix bug and refactor input buffer padding.

- Fixes a bug using realloc with a memory area that is declared const which
lead to a crash in MediaPlayer playing big_buck_bunny_720p_stereo.ogg.
- The refactoring introduces a strict separation between const memory areas
(chunk data read from GetNextChunk()) and mutable memory areas
(fVideoChunkBuffer) by using a copy operation instead of a casted
assignment operation.
- Updated documentation accordingly.
- Besides fixing the bug, there is no functional change intended.


# 6defcb6c 05-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out loading next video chunk.

- Main reason for refactoring was to increase readability of
_DecodeNextVideoFrame() by simplifying it. Refactoring was tested
successfully for no functional change with mpeg2_decoder_test.
- Reindented the method definition in the header file so that the new method
_LoadNextVideoChunkIfNeededAndUpdateStartTime() fits into 80 chars per line.
Reindentdation is applied to methods only as the member variables have no
space left for reindentation.
- Update documentation accordingly.
- Fix wording of audio part to audio path.
- No functional change intended.


# 2d83b841 04-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement video input buffer padding.

- Padding is required by FFMPEG for correct operation of all video decoders.
FFMPEG performs some speed optimizations under the hood that may lead to
reading over the end of the chunk buffer wouldn't there have been padding
applied.
- Note: Padding is required for audio decoders, too. I will tackle this in some
later commits. For the time being we have a degradation in code reuse, due to
different memory ownership of chunk buffers in audio and video decoder path.
Audio path must not care about freeing chunk buffers whereas video path must.
- Fix coding style and some typos.
- Update documentation accordingly.


# a335ec82 04-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement flushing of video frames from decoder.

- Video frames still contained in the video decoder are now flushed when there
are no encoded data chunks left (signaled by B_LAST_BUFFER_ERROR).
- New code was successfully tested with mpeg2_decoder_test. The last test image
is now decoded, too, resulting in a bump of the expected number of decoded
images.
- Refactor code to support flushing -and- keep the readability at a sane level.
- Remove some uncommented code for the sake of readability.
- Documentation updated accordingly.


# 62320bde 03-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Automatic detection of video decoding parameters.

- Kudos to Marcus Overhagen for laying out the general idea of automatic
detection by sharing some of his dvb code examples with me.
- Simplify pixel format search code by removing the loop and let FFMPEG
decide what pixel format to use based on the actual video data.
- Automatically detect the video frame rate based on the actual video data.
- Remove fOutputVideoFormat to avoid synchronizing values in two distinct
places. The member variable fHeader is the main place for important decoder
parameters now.
- Introduce fOutputColorSpace containing the color space that was previously
tracked in the fOutputVideoFormat member variable.
- Update the documentation accordingly.


# 60909c1e 03-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement and use calculation of bytes per row.


# 4f4d9891 03-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Extract video aspect ratio calculation code.

- Also make use of the extracted code in the AVCodecDecoder class.
- Enhance some documentation and fix some coding style violations.
- No functional change intended.


# f345d827 29-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Code styles, typos and code deduplication.

- Kudos to stippi for taking the time pointing those out :)
http://www.freelists.org/post/haiku-commits/haiku-hrev47576-srcaddonsmediapluginsffmpeg,1
- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# f7831362 26-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Fix doxygen style and typo.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# 97f5a12f 26-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Simplify start time calculation of video frame.

- We let FFMPEG keep track of the correct relationship between presentation
start time of the encoded video frame and the resulting decoded video frame.
This simplyfies our code, meaning less lines of code to maintain :)

- Update documentation and pointing out some corner cases when calculating the
correct presentation start time of a decoded video frame under certain
circumstances.

- Fix doxygen: Use doxygen style instead of javadoc style.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# 254a5340 24-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Refactor out update of media_header.

- Main purpose is to make reading the function DecodeNextFrame() easier on the
eyes, by moving out auxiliary code.
Note: The media_header update code for the start_time is still left in
DecodeNextFrame(). This will be addressed in a later commit specially
targetted on handling start_time calculations for incomplete video frames.

- Also updated / added some documentation.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# db59a667 17-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Implement decoding of streamed video data.

- This commit makes the mpeg2_decoder_test successfully decode the test video
into 84 consecutive PNG images, yeah :)

- If this commit broke playing video files for you please file a bug report.
I've tested only with one video file (big_buck_bunny_720p_stereo.ogg) that
everything still works.

- The implementation has some shortcomings though, that will be addressed with
some later commits:
1. Start time of media header is wrongly calculated. At the moment we are
using the start time of the first encoded data chunk we read via
GetNextChunk(). This works only for chunk that contain one and exactly
one frame, but not for chunks that contain the end or middle of a frame.
2. Fields of the media header aren't updated when there is a format change
in the middle of the video stream (for example the pixel aspect ratio
might change in the middle of a DVB video stream (e.g. switch from 4:3
to 16:9)).

- Also fix a potential bug, where the CODEC_FLAG_TRUNCATED flag was always
set, due to missing brackets.

Signed-off-by: Colin Günther <coling@gmx.de>


# 70a9edbb 15-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Tell the FFMPEG library to handle incomplete data.

- It is just one flag that needs to be set, so that streaming video data can be
handled by the FFMPEG library.

- For reference: This flag is based on FFMPEG's 0.10.2 video decode example
(doc/example/decoding_encoding.c).

- The _DecodeNextVideoFrame() method needs to be adjusted (still to come), to
take streamed data into account. So the flag on its own doesn't help, but it
is a reasonable step in that direction.

Signed-off-by: Colin Günther <coling@gmx.de>


# 0adda4f6 15-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Refactor video decoding function.

- Factor out the deinterlacing and color converting part to make the code more
readable. This makes it easier to understand which code belongs to the actual
decoding process and which code to the post processing.

- There seems to be no performance impact involved (I just looked at the spikes
of the process manager) in factoring out this part, but one can always inline
the method if a closer performance assesment (e.g. by enabling the profiling
the existing profiling code) suggests so.

- Document the _DecodeVideo() method a little bit. Maybe someone can document
the info parameter, as I'm a little bit clueless here.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>
(cherry picked from commit c5fa095fa73d47e75a46cfc138a56028fcc01819)


# 172c55fa 15-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Refactor video decoding function.

- We factor out the code that does the decoding, deinterlacing and color space
converting into its own function. This prepares auto detection of video frame
properties in a later commit. Auto detection means (for example), that you
don't need to know the size of the decoded video frame -before- intitializing
the video codec as it is the case with the current implementation.

- Use the already existent private member variable fHeader to fill out and
return video frame properties.

- Rename some variables to be more self describing.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>
(cherry picked from commit 6beab04f48e98022041895750f38c5a35a5f4f9e)


# 9e52cc74 12-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Use member variables instead of local ones.

- This small refactoring is in preparation for implementing decoding of partial
video frame data, where one needs to preserve encoded data between multiple
calls to AVCodecDecoder::_DecodeVideo().

- Note: The names fChunkBuffer and fChunkBufferSize are open for discussion.
I'd rather prefer fEncodedDataChunkBuffer and fEncodedDataChunkBufferSize.
But I'd like to take small refactoring steps, and changing the naming would
also touch the AVCodecDecoder::_DecodeAudio() function. I'd rather focus
on improving the video part for now, leaving the audio part alone.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>
(cherry picked from commit f2da1e752458b926aebe50642bf6af19e9903f17)


# 1a37a812 04-Dec-2013 Jerome Duval <jerome.duval@gmail.com>

ffmpeg: fix x86_64 build, remove libbz2

* AVCodecDecoder: for x86_64, use libswscale, asm is only for x86.
* CpuCapabilities: init capabilities to zero, fixes style.
* gfx_util.cpp: protect x86 specific code, fallback to C.
* x86_64: don't include unneeded x86 stuff.
* all arch: libbz2 is a build feature.


# 80ee381a 29-Apr-2012 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: use the cpu count as decoding thread count.


# b95fa248 11-Apr-2012 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: don't use deprecated API in AVCodecDecoder.


# 5b93b447 21-Mar-2012 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: updated gcc2 package and fixed crashes on exit.

* replaced calls to free() with calls to av_free().
* updated gcc2 package to disable SSE and a few options like we had
before with 0.6.


# 954d70d8 24-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

* Renamed fAudioTempPacket to fTempPacket and use it for calling
the new video decoding function. This just avoids a warning
generated from the libavcodec sources. The function used before
did the exact same thing...
* Maintain fStartTime correctly in _DecodeVideo(). Don't overwrite
it with a calculated starttime in Decode(). This will allow drift
to bubble up to the higher layers.
* Do not use the previously required hack to close and reopen the
AVCodec after seeking. avcodec_flush_buffers() seems to work
fine now, and for certain stream types (MPEG1, MPEG2 video for
example) the keyframe is correctly used after seeking.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38806 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c1e73fbf 22-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

Enabled any and all decoders and demuxers which are currently compiled into
FFmpeg. It's a bit sad, but this obsoletes pretty much all other decoder
and reader plugins. Some of them were built on external libraries as well
(AC3 (not part of default image anyway, since it's GPL), APE, MusePack),
so it's not really a big difference to using FFmpeg as external library.
The format matching is greatly simplified by using B_MISC_FORMAT_FAMILY
for everything but raw audio, and the actual FFmpeg CodecID as codec tag.
The downside of this is that the AVFormatReader can no longer be used with
other decoder plugins, but it would be easy to add special cases for native
decoders we wish to support. Obviously the out of the box support for file
formats and decoders has greatly increased with this change, so there has
to be a pretty good reason now for writing a "native" decoder or reader.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38786 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2e54e93f 18-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

Finall changed the Seek() method of Decoder plug-ins to
SeekedTo(), since it's only informative to decoders. They
can't modify the seeked frame/time. This also mirrors what
all existing decoders were doing in Seek(). BMediaTrack
is simplified accordingly (resolved two TODOs).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38705 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5a6b18e9 14-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

* Print the performance stats every five frames, and reset
the counters, so it's not the average for the entire
decoding time, but for the last five frames. This gives
a more accurate picture of what's going on.
* Added NOTE about possibly removing the SWS version of the
colorspace conversion code unless it's used for otherwise
unsupported conversions. David's code is about 40% faster
in my tests (nice job!).
* Free the sws context in NegotiateVideoFormat, if necessary.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38651 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b4a9b7c2 01-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

* Actually use the client suggested buffer size.
* When the client didn't suggest it, take the sample
size into account.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38494 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d5479a3b 27-Aug-2010 Stephan Aßmus <superstippi@gmx.de>

* Use the new avcodec_decode_audio3() call, avcodec_decode_audio2()
gives the deprecated warning... We need to cache an AVPacket for this.
* Check the allocation of fOutputBuffer.
* When seeking, we need to flush the already decoded stuff
in fOutputBuffer, and throw away the last chunk buffer as well.
* Handle an incomplete input format at least to the point of not
crashing with a divide error (mp3_reader would give us such an
incomplete format for example).
* _DecodeAudio():
- Fixed some edge cases in the audio decoding loop: avcodec_decode_audio3()
can return a 0 length, which means no error, but no decoded frames
either. ffplay throws away the chunk in this case, do the same.
- Convert some invalid situations that were printf()s into debugger()s.
- Add much more comments to explain how everything works.
* Fixed the occasional coding style issue.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38400 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ba0f80c4 23-Jul-2010 Stephan Aßmus <superstippi@gmx.de>

* Split debug output into general, audio and video (video output not done).
* Set the AVContext->frame_size, though I don't think it has any effect.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37707 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 96f1b483 08-Jan-2010 David McPaul <dlmcpaul@gmail.com>

use width and height when deciding on which conversion routine to select. Remove some checks per frame from sse2 conversion routines. Hopefully it still handles misaligned buffers ok. Too many tests were hurting performance

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34945 a95241bf-73f2-0310-859d-f6bbb57e9c96


# dfddb9f4 06-Jan-2010 Stephan Aßmus <superstippi@gmx.de>

* Optionally use libswscale for color space conversion. Have not done any
performance tests, but I wrote this code before David got around to improve
his color space assembler code and didn't want to throw it away. Turned
off for the time being, since David's version works fine.
* Supply a codec sub_id in the media_codec_info. This allows matching
decoders to encoders, which comes in handy for Smart Rendering in Clockwerk.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34931 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ed4313bc 29-Sep-2009 Stephan Aßmus <superstippi@gmx.de>

* Improvements in tracing.
* Added TODO about a probable mix-up to use the media_format meta data
because the FFmpeg Reader plug-in forgot to set the info-buffer correctly
from GetStreamInfo().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33355 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6bfbea62 19-Sep-2009 David McPaul <dlmcpaul@gmail.com>

Added SSE2 yuv to rgb conversion code. This code needs to move into the media kit though

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33200 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f0bdc769 21-Aug-2009 Jérôme Duval <korli@users.berlios.de>

* synced with ffmpeg-r19678, keeping gcc2 compiler #ifdef we introduced, build only tested on Haiku gcc2
* activated ac3 audio file format support
* uses format metadata to keep the codec context extra data (now needed for flac)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32597 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e4845287 07-Aug-2009 Stephan Aßmus <superstippi@gmx.de>

* In the AVCodecDecoder, use the audio format of the original input format,
but specify it to 16bits/sample if it's still a wildcard. Make sure to
allocate the scrub buffer with the correct sample size (was hardcoded to 2
bytes per sample).
* In the AVFormatReader, specify the sample format for B_MEDIA_ENCODED_AUDIO.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32185 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 037d0522 04-Aug-2009 Stephan Aßmus <superstippi@gmx.de>

I have no idea how that ended up there... set the decoded audio format correctly
again. Should fix playback of any file where the ffmpeg plugin was responsible
for sound. (The symptoms were a crash into the debugger because of an unspecified
audio format...)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32107 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3ae83fe3 31-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Automatic whitespace cleanup.
* media_decode_info member was never used.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32015 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 43592489 30-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

Hack to automatically deinterlace video, this needs to be improved later on,
but is better than before in any case. The deinterlacing is nothing fancy,
basically, it just drops the first field... the implementation to use this
is also not as efficient as it could be, it currently allocates a temporary
frame always...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31996 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6e94d298 15-Jul-2009 Jérôme Duval <korli@users.berlios.de>

added flac to the codec table and the demuxer table.
audio format is now taken into account by the decoder when negociating the media output format.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31597 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6fd02522 14-Jul-2009 Jérôme Duval <korli@users.berlios.de>

fix debug mode


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31574 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 219858ad 10-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Simplified "extra data" handling/allocation code a bit.
* Added debugging facility to dump the first 100 packets of a video stream
to a debug file on the Desktop.
* When needing to flush packets, avcodec_flush_buffers() is unfortunately
not reliable. For audio codecs, the work around was to close and reopen
the codec in Seek(). Do this also for video codecs. Makes H.264 more
reliable here.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31503 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 12a9eb5d 08-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Coding style cleanup, some removal of dead code.
* Refactored NegotiateOutputFormat() and Decode() into two separate private
methods each, one for video and one for audio.
* Keep reading chunks when video decoding, until we have got a picture. This
gets us scrambled video instead of a black picture for h264 in mpegts.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31457 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 668ed70b 01-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Use a static global object to initialize libavformat and libavcodec.
* Turn off tracing in the AVCodecDecoder which I accidentally turned on in
a previous commit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31366 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 27f6fb6c 01-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Renamed avcodec folder to ffmpeg.
* Cleaned up plugins Jamfile.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31359 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 278af8e281390a344b2271a27dffc4a6798200eb 30-Aug-2015 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg: check against correct version constants.

54.23.x is ffmpeg 0.11, which still has "CodecID" (and x>0).


# f618c89e17deda1047a747bec2685b82eac48b79 30-Aug-2015 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg: detect the library version the right way.

* Fixes the build by detecting the library version using the provided
constants, instead of guessing from the compiler version.


# 9e5c694668556b60e49a49e6708bfb550fc6ce1b 30-Aug-2015 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg plugin: remove more deprecated functions.

These were all deprecated between releases 0.6 and 0.10 of ffmpeg,
except for one change (renaming of CodecID to AVCodecID) which we can
work around with a typedef. The deprecated functions were still
available in 0.11, but were removed later on after several years of
deprecation.

This makes it possible to build our plugin with any ffmpeg version
between 0.10 and 2.7, so we can now experiment with updating to 2.7 at
least for the gcc4 builds.


# 1148ea734e207ac0153d3e206c8618644a22fb96 10-Dec-2014 Adrien Destugues <pulkomandy@gmail.com>

AVCodecDecoder: remove annoying assert.

According to Colin this is not supposed to happen, but it does. Since
the affected video otherwise decodes just fine, I think it is safe to
disable the assert and not annoy our users.

Fixes #11409.


# ff68ae983711899f5b6efc1101b3d7cbd7f536b2 09-Dec-2014 Adrien Destugues <pulkomandy@gmail.com>

ffmpeg: disable runtime frame rate changes support.

This change was introduced by Colin for DVB-T support, however it also
breaks the timing of several MP4 files. The code is incomplete and
computes slightly to very wrong frame rates (one video plays about twice
as fast as needed, another one attempts to play at 30000 FPS).

I suspect similar problems would be found when changing the frame rate
in DVB-T streams in the same way, so I'm disabling this code for now
until a correct solution is found or we manage to use a newer version of
ffmpeg (where there is an actual framerate field in the format and it
doesn't need to be derived from the time_base anymore).

This restores the previous behavior of computing the framerate at the
AVFormatReader level, that is, once per stream, rather than once per
frame. At the stream level we have enough data to compute an "average"
frame rate, and there is also an "r_frame_rate" (real frame rate) which
may be usable for this. Not having working DVB-T hardware to experiment
with that yet, I'll leave it to others.

Fixes #11283 and the last remaining problem in #4512.


# 4ff7c2cc61219311b2d0c43377974d4c8dead297 25-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Small refactoring in audio path.

- Lazy initializing the fDecodedData variable fits best in
_ResetRawDecodedAudio() as fRawDecodedAudio is all about managing properties
of fDecodedData. So fDecodedData having some memory allocated is seen as a
property here.

- Updated documentation accordingly

- No functional change intended.


# fe1eb3c1c10c08e0af4e74a1936a8651e6dda9f8 25-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix performance regression on video path.

- For best performance the color conversion function expects a memory location
aligned to 32 bytes. Without that alignment the color conversion function
falls back to a slower conversion path. This fix was measured via
DO_PROFILING and tested with various 1080p video files.


# 1c5f18308c16648341884fe99a98a54413c7c55d 25-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix correct decoding of first video frame.

- The first decoded video frame was always zero bytes large, due to passing the
wrong linesize to the color conversion function. The field containing the
right linesize (fHeader.u.raw_video.bytes_per_row) simply wasn't initialized
yet. Fix it by updating fHeader first before applying deinterlacing and color
converting to the decoded video frame.
Tested with mpeg2_decoder_test where the first picture now isn't empty
(black) anymore.


# f7f670220327c603ba7d3a7e710587fc5544c408 24-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement audio input buffer padding.

- Padding is required by FFMPEG for correct operation of all audio decoders.
FFMPEG performs some speed optimizations under the hood that may lead to
reading over the end of the chunk buffer wouldn't there have been padding
applied.

- Resolve TODOs by unifying fVideoChunkBuffer and fChunkBuffer back into
fChunkBuffer because audio path is responsible for freeing fChunkBuffer now.
Resolved TODOs apply to the replacing fVideoChunkBuffer variable by
fChunkBuffer, rename some methods by removing the "Video" part, collapse two
methods into one (_LoadNextChunkIfNeededAndAssignStartTime()).
No functional change intended.

- Enhance "logging stream to file" functionality to write to distinct logging
files for audio and video. Before this commit one could only log video
streams. But with unifying the _LoadNextChunkIfNeededAndAssignStartTime()
audio streams gained the logging functionality for free. But now audio and
video streams would be written in the same log file when watching a media
file containing both audio and video. This is prevented by the distinct
logging mentioned above.

- Update documentation accordingly.


# 3c68ae7c581191fbb32cd0da52c9a24c666b9814 24-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out copying of audio format properties.

- Main reasons for this refactoring of negotiation steps are to increase
readability and to be on par with the video path.

- Rearrange some negotiation steps in video path to be on par with audio path.

- Add documentation for the new method and update existing documentation
accordingly.

- No functional change intended.


# ffb0f5db8e4976139e53bf333d4af7052b26167c 23-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Automatic detection of audio decoding parameters.

- Kudos to Marcus Overhagen for laying out the general idea of automatic
detection by sharing some of his dvb code examples with me.
- Automatically detect the audio frame rate, channel count and sample format.
- Share audio sample format conversion code between AVFormatReader and
AVCodecDecoder.
- Tested with several video and audio files via MediaPlayer.
- Tested also with test case mp3_decoder_test -after- removing the hard coded
audio decoding parameters. Although the test shows that auto detection is
working (via stepping through the auto detection code path) the complete test
is still failing, due to missing implementation of incomplete audio frame
decoding.
- Add and update the documentation accordingly.


# 1a963de4e01f9215ab8ea56ef5f50df7da307986 23-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out audio frames chunk decoding.

- Main purpose is to prepare auto detection of audio frame properties for
media formats that encode those properties in the frames themself (e.g. MP3)
instead of in the container format (e.g. WMA).
The main difference between akin named methods _DecodeNextAudioFrame() and
_DecodeNextAudioFrameChunk() is that the former method deals with providing
the exact number of audio frames expected by the caller of
BMediaDecoder::Decode() and the latter deals with decoding any number of
audio frames at all.

- New documentation added and existing documentationupdated accordingly.

- No functional change intended.


# 3c6f9c1087639138b56e0412a6ce997b29223603 22-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fill out more media header fields in audio path.

- Some small refactoring when resetting fRawDecodedAudio. Instead of letting
FFMPEG reset fRawDecodedAudio we do it manually to preserve the allocated
memory in fRawDecodedAudio->opaque (otherwise FFMPEG's
avcodec_get_frame_defaults() would NULLify the opaque pointer without
releasing the allocated memory.

- Keep track of the total size of fDecodedData in fRawDecodedAudio->linesize[0]
instead of relying on calculating it every time it is needed. This makes the
code more comprehensible.


# 1b8bbb509aacb9b7a200bfdcf82e4ea0bb66a7d2 22-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out checking of invalid conditions in audio path.

- Main reason for this refactoring is to increase readability and thus make
audio decode path more comprehensible.

- Added documentation for the new method accordingly.

- Small change in calculating the decoded data size to clear when error occurs
during decoding. This way it is more readable and more consistent with
calculations of decoded data size on other locations.

- No functional change intended.


# ca5c686d9352a8b178549b06fcb2a74488bb5caa 22-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out moving audio frames from buffer.

- Main reason for this refactoring is to increase readability and thus make the
audio decode path more comprehensible.

- Added documentation for the new method accordingly.

- No functional change intended.


# 7dc2773cffbe6f56a77589bb709665ab3d15903e 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out chunk loading in audio path.

- Main reasons are to increase readability of audio path and to demonstrate
that chunk loading in audio and video path is the same code that can be
focused in one method (instead of two at the moment). Added a TODO for
collapsing both methods into one and the conditions that must hold true to
do so (just in case I'll be hitted by a bus and someone else has to proceed).
Collapsing is scheduled for a later commit.

- Added documentation for the new method accordingly.

- Make use of full line length in comments of
_LoadNextVideoChunkIfNeededAndAssignStartTime().

- No functional change intended.


# 463f34021e4d12efab51ae3e8ab82b1f405df59c 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out actual audio decoding part.

- Main reason for this refactoring is to increase readability and thus make the
audio decode path more comprehensible.

- Added documentation for the new method accordingly.

- Small refactoring for detecting when to update fRawDecodedAudio's properties.
This is a preparation step for factoring out the flushing of the
fDecodedDataBuffer in a later commit.

- No functional change intended.


# 815d18fb53096745da82906a6f326fa597412523 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor start time handling in audio path.

- FFMPEG handles the relationship of start time between encoded and decoded
audio data now by using the fTempPacket->dts and the
fDecodedDataBuffer->pkt_dts fields. We still have to manually keep track of
start times for consecutive audio frames though to support returning a number
of audio frames that may assembled of partial AVFrames.

- The start time of the very first audio frame data packet returned by Decode()
is now correctly calculated based on GetNextChunk() start times instead of
being always zero.

- Introduce fRawDecodedAudio that serves as a container to store properties of
the audio frames stored in fDecodedData. This prepares the population of the
fHeader structure with audio frame properties needed to allow clients of
BMediaDecoder::Decode() detect audio format changes in a later commit.

- Remove fStartTime as it is superflous now.


# 7f485803cd06f395f61a378fe6c2a986eb8966e9 21-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Print debug output for audio frames, too

- Also change what is printed for video frames. Currently both
debug_fframe_[audio|video] are used in AVCodecDecoder only and thus are
streamlined for their usage there. For example we print the AVFrame.pkt_dts
field instead of the AVFrame.pkt field because the later one is never touched
by AVCodecDecoders usage of the FFMPEG library.
Note: AVFrame.pkt being never touched means that it always contains the value
AV_NOPTS_VALUE making it less useful for debug purposes.


# b82ef8bc15614a52394f5f5626b719530e01cfa5 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor scope of fTempPacket in audio path.

- There are two main reasons for this refactoring:
1. Prepare using FFMPEGs functionality of audio frame start time assignment
(instead of rolling it ourself) like already done for the video path
(see _LoadNextVideoChunkIfNeededAndAssignStartTime() for reference).
2. Get rid of fChunkBufferOffset (this is a minor reason though).

- Untangle some of the conditional checks to increase readability.

- No functional change intended.


# 3bca609810310998daf639e27fbdcaa22cf49210 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Rename some variables in audio path.

- Make the difference between fDecodedData and fDecodedDataBuffer more clear.

- No functional change intended.


# 85371234ea80acd42cfbcc64d82ce0df79fb1e7b 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor audio decoding method into two.

- First method is solely responsible to fill the audio output buffer with
already decoded audio frames.
Second method is solely responsible for decoding the encoded audio data and
put it in the decoded audio output buffer for further processing with the
first method.
This prepares auto detection of audio frame properties for audio formats
where the properties are contained within the encoded audio frame (e.g. MP3),
instead within the audio container format (e.g. WMA). Implementing auto
detection is scheduled for a later commit though.

- Added documentation accordingly.

- No functional change intended.


# 54b392b4cc060fffd7ae2cb10be7bea28ff8b301 19-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Some cleanups.

- Use name that correctly reflects the return value of avcodec_decode_video2().
- Make DO_PROFILING code path of AVCodecDecoder compile again.
- No functional change intended.


# 75bd62e8687256d9b89c870c4ea68a5fb4138082 20-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix playing video files.

- This should fix the bug where video files that played well before the recent
changes to the FFMPEG Plugin didn't play anymore. Now we apply the essential
video container properties (that were passed by with Setup()) to the
AVCodecContext. Some video formats simply store those properties in the
container only (e.g. AVI, WMV) and not in the video frames itself
(e.g. MPEG2).
Tested with several files from samples.ffmpeg.org and from the FATE suite of
FFMPEG.


# ed9de7dfca10fd536b288ff84c8af840e1c9111e 10-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix video start_time handling

- I misinterpreted the semantics of reordered_opaque. I thought it would
establish the correct relationship between the start_time returned by
GetNextChunk() and the next video frame successfully decoded. But for this
to work reordered_opaque expects to be filled with presentation time stamps.
A series of presentation time stamps may be jumping back in time due to the
presence of B-frames. The decoded frame presentation time stamps series would
then be ordered in a monotonically increased way.
But actually GetNextChunk() always returns monotonically increasing start
times. Mapping this behaviour to FFMPEG's expectations means labeling those
start times as decoding time stamps (dts). Though for those start times to be
related to the correct decoded video frames you have to assign the start time
with the AVPacket containing the data to be decoded.

- This commit finally makes DVB video playback working for me with the TV app.
Though no audio yet.

- The documentation was updated accordingly.


# b77f1724a28bb187ebfdd7334ce1d642479e54c2 07-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Calculate media_header.size_used field

- This field is needed by the dvb.media_addon to detect a format change so
fill it with the correct value.
- Updated documentation accordingly to reflect reordered function calls and new
assumptions based on the function call ordering.


# 6063c02ef91c615f2fa28468f16c40b9b8ba1164 05-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Fix bug and refactor input buffer padding.

- Fixes a bug using realloc with a memory area that is declared const which
lead to a crash in MediaPlayer playing big_buck_bunny_720p_stereo.ogg.
- The refactoring introduces a strict separation between const memory areas
(chunk data read from GetNextChunk()) and mutable memory areas
(fVideoChunkBuffer) by using a copy operation instead of a casted
assignment operation.
- Updated documentation accordingly.
- Besides fixing the bug, there is no functional change intended.


# 6defcb6c6dcc4175fd38477777c369416c0ca498 05-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Refactor out loading next video chunk.

- Main reason for refactoring was to increase readability of
_DecodeNextVideoFrame() by simplifying it. Refactoring was tested
successfully for no functional change with mpeg2_decoder_test.
- Reindented the method definition in the header file so that the new method
_LoadNextVideoChunkIfNeededAndUpdateStartTime() fits into 80 chars per line.
Reindentdation is applied to methods only as the member variables have no
space left for reindentation.
- Update documentation accordingly.
- Fix wording of audio part to audio path.
- No functional change intended.


# 2d83b8419cb16ba1733ebf42432ea5b953b5eee7 04-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement video input buffer padding.

- Padding is required by FFMPEG for correct operation of all video decoders.
FFMPEG performs some speed optimizations under the hood that may lead to
reading over the end of the chunk buffer wouldn't there have been padding
applied.
- Note: Padding is required for audio decoders, too. I will tackle this in some
later commits. For the time being we have a degradation in code reuse, due to
different memory ownership of chunk buffers in audio and video decoder path.
Audio path must not care about freeing chunk buffers whereas video path must.
- Fix coding style and some typos.
- Update documentation accordingly.


# a335ec823a394d84383d652630d13135e4338a56 04-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement flushing of video frames from decoder.

- Video frames still contained in the video decoder are now flushed when there
are no encoded data chunks left (signaled by B_LAST_BUFFER_ERROR).
- New code was successfully tested with mpeg2_decoder_test. The last test image
is now decoded, too, resulting in a bump of the expected number of decoded
images.
- Refactor code to support flushing -and- keep the readability at a sane level.
- Remove some uncommented code for the sake of readability.
- Documentation updated accordingly.


# 62320bdea233d6f3d321ea20b922dde8a0c711d9 03-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Automatic detection of video decoding parameters.

- Kudos to Marcus Overhagen for laying out the general idea of automatic
detection by sharing some of his dvb code examples with me.
- Simplify pixel format search code by removing the loop and let FFMPEG
decide what pixel format to use based on the actual video data.
- Automatically detect the video frame rate based on the actual video data.
- Remove fOutputVideoFormat to avoid synchronizing values in two distinct
places. The member variable fHeader is the main place for important decoder
parameters now.
- Introduce fOutputColorSpace containing the color space that was previously
tracked in the fOutputVideoFormat member variable.
- Update the documentation accordingly.


# 60909c1e194c097674aa80ce0da5e50cb4fab427 03-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Implement and use calculation of bytes per row.


# 4f4d98911a40a7683106c644fec459c9dd115df2 03-Aug-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Extract video aspect ratio calculation code.

- Also make use of the extracted code in the AVCodecDecoder class.
- Enhance some documentation and fix some coding style violations.
- No functional change intended.


# f345d82773c0fb926f4740e5f851f5790a0d8d97 29-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG Plugin: Code styles, typos and code deduplication.

- Kudos to stippi for taking the time pointing those out :)
http://www.freelists.org/post/haiku-commits/haiku-hrev47576-srcaddonsmediapluginsffmpeg,1
- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# f78313627450a8c919f7ddb70f79f9f0662ee661 26-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Fix doxygen style and typo.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# 97f5a12f3692b17cb93edeb0f37939ee0290fc7d 26-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Simplify start time calculation of video frame.

- We let FFMPEG keep track of the correct relationship between presentation
start time of the encoded video frame and the resulting decoded video frame.
This simplyfies our code, meaning less lines of code to maintain :)

- Update documentation and pointing out some corner cases when calculating the
correct presentation start time of a decoded video frame under certain
circumstances.

- Fix doxygen: Use doxygen style instead of javadoc style.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# 254a53409eaa75e6f21d56b4f5f0bfcdd427c6b3 24-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Refactor out update of media_header.

- Main purpose is to make reading the function DecodeNextFrame() easier on the
eyes, by moving out auxiliary code.
Note: The media_header update code for the start_time is still left in
DecodeNextFrame(). This will be addressed in a later commit specially
targetted on handling start_time calculations for incomplete video frames.

- Also updated / added some documentation.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>


# db59a667044f697d0bb8fdff23597105cd7df4b2 17-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG-Plugin: Implement decoding of streamed video data.

- This commit makes the mpeg2_decoder_test successfully decode the test video
into 84 consecutive PNG images, yeah :)

- If this commit broke playing video files for you please file a bug report.
I've tested only with one video file (big_buck_bunny_720p_stereo.ogg) that
everything still works.

- The implementation has some shortcomings though, that will be addressed with
some later commits:
1. Start time of media header is wrongly calculated. At the moment we are
using the start time of the first encoded data chunk we read via
GetNextChunk(). This works only for chunk that contain one and exactly
one frame, but not for chunks that contain the end or middle of a frame.
2. Fields of the media header aren't updated when there is a format change
in the middle of the video stream (for example the pixel aspect ratio
might change in the middle of a DVB video stream (e.g. switch from 4:3
to 16:9)).

- Also fix a potential bug, where the CODEC_FLAG_TRUNCATED flag was always
set, due to missing brackets.

Signed-off-by: Colin Günther <coling@gmx.de>


# 70a9edbb1181302caff7f4d1147e60bfa124568a 15-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Tell the FFMPEG library to handle incomplete data.

- It is just one flag that needs to be set, so that streaming video data can be
handled by the FFMPEG library.

- For reference: This flag is based on FFMPEG's 0.10.2 video decode example
(doc/example/decoding_encoding.c).

- The _DecodeNextVideoFrame() method needs to be adjusted (still to come), to
take streamed data into account. So the flag on its own doesn't help, but it
is a reasonable step in that direction.

Signed-off-by: Colin Günther <coling@gmx.de>


# 0adda4f68fd08e07ecd04df298e61974888e886a 15-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Refactor video decoding function.

- Factor out the deinterlacing and color converting part to make the code more
readable. This makes it easier to understand which code belongs to the actual
decoding process and which code to the post processing.

- There seems to be no performance impact involved (I just looked at the spikes
of the process manager) in factoring out this part, but one can always inline
the method if a closer performance assesment (e.g. by enabling the profiling
the existing profiling code) suggests so.

- Document the _DecodeVideo() method a little bit. Maybe someone can document
the info parameter, as I'm a little bit clueless here.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>
(cherry picked from commit c5fa095fa73d47e75a46cfc138a56028fcc01819)


# 172c55faf1efe2e399094d8830f6b4577fb840bb 15-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Refactor video decoding function.

- We factor out the code that does the decoding, deinterlacing and color space
converting into its own function. This prepares auto detection of video frame
properties in a later commit. Auto detection means (for example), that you
don't need to know the size of the decoded video frame -before- intitializing
the video codec as it is the case with the current implementation.

- Use the already existent private member variable fHeader to fill out and
return video frame properties.

- Rename some variables to be more self describing.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>
(cherry picked from commit 6beab04f48e98022041895750f38c5a35a5f4f9e)


# 9e52cc748084e62e6f1b6dc42038c84cde31f3ff 12-Jul-2014 Colin Günther <coling@gmx.de>

FFMPEG plugin: Use member variables instead of local ones.

- This small refactoring is in preparation for implementing decoding of partial
video frame data, where one needs to preserve encoded data between multiple
calls to AVCodecDecoder::_DecodeVideo().

- Note: The names fChunkBuffer and fChunkBufferSize are open for discussion.
I'd rather prefer fEncodedDataChunkBuffer and fEncodedDataChunkBufferSize.
But I'd like to take small refactoring steps, and changing the naming would
also touch the AVCodecDecoder::_DecodeAudio() function. I'd rather focus
on improving the video part for now, leaving the audio part alone.

- No functional change intended.

Signed-off-by: Colin Günther <coling@gmx.de>
(cherry picked from commit f2da1e752458b926aebe50642bf6af19e9903f17)


# 1a37a812a4ba34aa61b1965209a5682941ac11ef 04-Dec-2013 Jerome Duval <jerome.duval@gmail.com>

ffmpeg: fix x86_64 build, remove libbz2

* AVCodecDecoder: for x86_64, use libswscale, asm is only for x86.
* CpuCapabilities: init capabilities to zero, fixes style.
* gfx_util.cpp: protect x86 specific code, fallback to C.
* x86_64: don't include unneeded x86 stuff.
* all arch: libbz2 is a build feature.


# 80ee381a5fbd49b1ae3f4601dc725ac433a8b3e5 29-Apr-2012 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: use the cpu count as decoding thread count.


# b95fa2488ad09133ca040fde61914b132680a079 11-Apr-2012 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: don't use deprecated API in AVCodecDecoder.


# 5b93b4477e61e42e4f5cc9a938bf8b1f06145d88 21-Mar-2012 Jérôme Duval <jerome.duval@gmail.com>

ffmpeg: updated gcc2 package and fixed crashes on exit.

* replaced calls to free() with calls to av_free().
* updated gcc2 package to disable SSE and a few options like we had
before with 0.6.


# 954d70d8c0335f3d77503973a4d5a04172b6d177 24-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

* Renamed fAudioTempPacket to fTempPacket and use it for calling
the new video decoding function. This just avoids a warning
generated from the libavcodec sources. The function used before
did the exact same thing...
* Maintain fStartTime correctly in _DecodeVideo(). Don't overwrite
it with a calculated starttime in Decode(). This will allow drift
to bubble up to the higher layers.
* Do not use the previously required hack to close and reopen the
AVCodec after seeking. avcodec_flush_buffers() seems to work
fine now, and for certain stream types (MPEG1, MPEG2 video for
example) the keyframe is correctly used after seeking.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38806 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c1e73fbf52c01d51df5e4e9e2ac0e4839bc2b0b3 22-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

Enabled any and all decoders and demuxers which are currently compiled into
FFmpeg. It's a bit sad, but this obsoletes pretty much all other decoder
and reader plugins. Some of them were built on external libraries as well
(AC3 (not part of default image anyway, since it's GPL), APE, MusePack),
so it's not really a big difference to using FFmpeg as external library.
The format matching is greatly simplified by using B_MISC_FORMAT_FAMILY
for everything but raw audio, and the actual FFmpeg CodecID as codec tag.
The downside of this is that the AVFormatReader can no longer be used with
other decoder plugins, but it would be easy to add special cases for native
decoders we wish to support. Obviously the out of the box support for file
formats and decoders has greatly increased with this change, so there has
to be a pretty good reason now for writing a "native" decoder or reader.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38786 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2e54e93fbf76098340f69d0d1bc9d82579fb0069 18-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

Finall changed the Seek() method of Decoder plug-ins to
SeekedTo(), since it's only informative to decoders. They
can't modify the seeked frame/time. This also mirrors what
all existing decoders were doing in Seek(). BMediaTrack
is simplified accordingly (resolved two TODOs).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38705 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5a6b18e9140272344c30bc91526547c96f3150d6 14-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

* Print the performance stats every five frames, and reset
the counters, so it's not the average for the entire
decoding time, but for the last five frames. This gives
a more accurate picture of what's going on.
* Added NOTE about possibly removing the SWS version of the
colorspace conversion code unless it's used for otherwise
unsupported conversions. David's code is about 40% faster
in my tests (nice job!).
* Free the sws context in NegotiateVideoFormat, if necessary.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38651 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b4a9b7c236793efc3c9a6344ec5687dcfdd17eca 01-Sep-2010 Stephan Aßmus <superstippi@gmx.de>

* Actually use the client suggested buffer size.
* When the client didn't suggest it, take the sample
size into account.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38494 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d5479a3bd0b0d308a04f7e3eec3e356831e04718 27-Aug-2010 Stephan Aßmus <superstippi@gmx.de>

* Use the new avcodec_decode_audio3() call, avcodec_decode_audio2()
gives the deprecated warning... We need to cache an AVPacket for this.
* Check the allocation of fOutputBuffer.
* When seeking, we need to flush the already decoded stuff
in fOutputBuffer, and throw away the last chunk buffer as well.
* Handle an incomplete input format at least to the point of not
crashing with a divide error (mp3_reader would give us such an
incomplete format for example).
* _DecodeAudio():
- Fixed some edge cases in the audio decoding loop: avcodec_decode_audio3()
can return a 0 length, which means no error, but no decoded frames
either. ffplay throws away the chunk in this case, do the same.
- Convert some invalid situations that were printf()s into debugger()s.
- Add much more comments to explain how everything works.
* Fixed the occasional coding style issue.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38400 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ba0f80c46b830bb383edff8aeff03c65cec33dc8 23-Jul-2010 Stephan Aßmus <superstippi@gmx.de>

* Split debug output into general, audio and video (video output not done).
* Set the AVContext->frame_size, though I don't think it has any effect.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37707 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 96f1b483e4423a8a8505d630dfbfd1d78a739987 08-Jan-2010 David McPaul <dlmcpaul@gmail.com>

use width and height when deciding on which conversion routine to select. Remove some checks per frame from sse2 conversion routines. Hopefully it still handles misaligned buffers ok. Too many tests were hurting performance

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34945 a95241bf-73f2-0310-859d-f6bbb57e9c96


# dfddb9f479469318442393ca4d4ed44cf90ca8e0 06-Jan-2010 Stephan Aßmus <superstippi@gmx.de>

* Optionally use libswscale for color space conversion. Have not done any
performance tests, but I wrote this code before David got around to improve
his color space assembler code and didn't want to throw it away. Turned
off for the time being, since David's version works fine.
* Supply a codec sub_id in the media_codec_info. This allows matching
decoders to encoders, which comes in handy for Smart Rendering in Clockwerk.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34931 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ed4313bca98521437cdeaf1d07e981539a11333a 29-Sep-2009 Stephan Aßmus <superstippi@gmx.de>

* Improvements in tracing.
* Added TODO about a probable mix-up to use the media_format meta data
because the FFmpeg Reader plug-in forgot to set the info-buffer correctly
from GetStreamInfo().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33355 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6bfbea62cd2e70f2ce97101d038c803ea8027393 19-Sep-2009 David McPaul <dlmcpaul@gmail.com>

Added SSE2 yuv to rgb conversion code. This code needs to move into the media kit though

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33200 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f0bdc7699c590eb99f05b6eb5a048bee73966335 21-Aug-2009 Jérôme Duval <korli@users.berlios.de>

* synced with ffmpeg-r19678, keeping gcc2 compiler #ifdef we introduced, build only tested on Haiku gcc2
* activated ac3 audio file format support
* uses format metadata to keep the codec context extra data (now needed for flac)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32597 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e48452878e24d88c23a3ff59243ce3bc6daabca2 07-Aug-2009 Stephan Aßmus <superstippi@gmx.de>

* In the AVCodecDecoder, use the audio format of the original input format,
but specify it to 16bits/sample if it's still a wildcard. Make sure to
allocate the scrub buffer with the correct sample size (was hardcoded to 2
bytes per sample).
* In the AVFormatReader, specify the sample format for B_MEDIA_ENCODED_AUDIO.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32185 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 037d052235fe213a2a35b67343f8cbe5a0454f0a 04-Aug-2009 Stephan Aßmus <superstippi@gmx.de>

I have no idea how that ended up there... set the decoded audio format correctly
again. Should fix playback of any file where the ffmpeg plugin was responsible
for sound. (The symptoms were a crash into the debugger because of an unspecified
audio format...)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32107 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3ae83fe3c711c3bee1f1fe955488f14914aa83a7 31-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Automatic whitespace cleanup.
* media_decode_info member was never used.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32015 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 435924897fc394f75a0bd450438517d388a54440 30-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

Hack to automatically deinterlace video, this needs to be improved later on,
but is better than before in any case. The deinterlacing is nothing fancy,
basically, it just drops the first field... the implementation to use this
is also not as efficient as it could be, it currently allocates a temporary
frame always...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31996 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6e94d298821f62c72c18cc1e0421bbe9465c5dc4 15-Jul-2009 Jérôme Duval <korli@users.berlios.de>

added flac to the codec table and the demuxer table.
audio format is now taken into account by the decoder when negociating the media output format.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31597 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6fd02522ea6a5f8c6f2687b615a3f029772b6ac1 14-Jul-2009 Jérôme Duval <korli@users.berlios.de>

fix debug mode


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31574 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 219858ad3191c35408fb3370481ba3b213a2edcc 10-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Simplified "extra data" handling/allocation code a bit.
* Added debugging facility to dump the first 100 packets of a video stream
to a debug file on the Desktop.
* When needing to flush packets, avcodec_flush_buffers() is unfortunately
not reliable. For audio codecs, the work around was to close and reopen
the codec in Seek(). Do this also for video codecs. Makes H.264 more
reliable here.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31503 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 12a9eb5d934906ac3d1ce00c96290b44ffeeaa18 08-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Coding style cleanup, some removal of dead code.
* Refactored NegotiateOutputFormat() and Decode() into two separate private
methods each, one for video and one for audio.
* Keep reading chunks when video decoding, until we have got a picture. This
gets us scrambled video instead of a black picture for h264 in mpegts.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31457 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 668ed70bd09305b90b04bfbaee6db847ca5c3d8f 01-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Use a static global object to initialize libavformat and libavcodec.
* Turn off tracing in the AVCodecDecoder which I accidentally turned on in
a previous commit.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31366 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 27f6fb6ce7c1050d845a500e26018ff97c5d573e 01-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

* Renamed avcodec folder to ffmpeg.
* Cleaned up plugins Jamfile.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31359 a95241bf-73f2-0310-859d-f6bbb57e9c96