History log of /haiku/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.h
Revision Date Author Comments
# 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>


# 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>


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

ffmpeg: avcodec_find_decoder returns a const AVCodec*

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


# 218a8c03 17-May-2019 Augustin Cavalier <waddlesplash@gmail.com>

Revert the Codec Kit.

All of Barrett's individual reverts have been squashed into this
one commit, save a few actual bugfixes.

Change-Id: Ib0a7d0a841d3ac40b1fca7372c58b7f9229bd1f0


# d33bd9ec 26-Nov-2018 Barrett17 <b.vitruvio@gmail.com>

Codec Kit: Introduce BCodecKit namespace


# cd564566 24-Nov-2018 Barrett17 <b.vitruvio@gmail.com>

ffmpeg: Update class names


# 082e4ae4 25-Nov-2018 Barrett17 <b.vitruvio@gmail.com>

Codec Kit: Rename files


# 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>


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

add-ons/media/ffmpeg: Use SWS for color-space conversion universally.

It seems to be as if not faster than the built-in method now as far
as I can tell, and this means one less arch-specific difference.
I haven't ripped all of it out yet, though.


# 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.


# 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


# 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.


# 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.


# 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?


# 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.


# 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.


# 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.


# 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.


# 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.


# 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.


# 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>


# 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>


# 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)


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

ffmpeg: don't use deprecated API in AVCodecDecoder.


# 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


# 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


# 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


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

Sorry, this was supposed to be part of the last commit...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33356 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


# 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


# 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


# 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.


# 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.


# 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.


# 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.


# 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.


# 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.


# 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>


# 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>


# 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)


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

ffmpeg: don't use deprecated API in AVCodecDecoder.


# 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


# 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


# 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


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

Sorry, this was supposed to be part of the last commit...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33356 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


# 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


# 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