diff --git a/src/add-ons/media/plugins/matroska/Jamfile b/src/add-ons/media/plugins/matroska/Jamfile index 4f92aa3fe3..3ab712ac83 100644 --- a/src/add-ons/media/plugins/matroska/Jamfile +++ b/src/add-ons/media/plugins/matroska/Jamfile @@ -6,7 +6,9 @@ UsePrivateHeaders media ; SubDirHdrs [ FDirName $(SUBDIR) libMatroskaParser ] ; Addon matroska : media plugins : + matroska_codecs.cpp matroska_reader.cpp + matroska_util.cpp : false : diff --git a/src/add-ons/media/plugins/matroska/matroska_codecs.cpp b/src/add-ons/media/plugins/matroska/matroska_codecs.cpp new file mode 100644 index 0000000000..a287b1fbcd --- /dev/null +++ b/src/add-ons/media/plugins/matroska/matroska_codecs.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2004, Marcus Overhagen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include +#include +#include "RawFormats.h" +#include "matroska_reader.h" diff --git a/src/add-ons/media/plugins/matroska/matroska_codecs.h b/src/add-ons/media/plugins/matroska/matroska_codecs.h new file mode 100644 index 0000000000..62f4a8f534 --- /dev/null +++ b/src/add-ons/media/plugins/matroska/matroska_codecs.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2004, Marcus Overhagen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _MATROSKA_CODECS_H +#define _MATROSKA_CODECS_H + + +#endif diff --git a/src/add-ons/media/plugins/matroska/matroska_reader.cpp b/src/add-ons/media/plugins/matroska/matroska_reader.cpp index 5ec4d1d752..68c2ecb007 100644 --- a/src/add-ons/media/plugins/matroska/matroska_reader.cpp +++ b/src/add-ons/media/plugins/matroska/matroska_reader.cpp @@ -31,6 +31,8 @@ #include #include "RawFormats.h" #include "matroska_reader.h" +#include "matroska_codecs.h" +#include "matroska_util.h" #define TRACE_MKV_READER #ifdef TRACE_MKV_READER @@ -57,9 +59,11 @@ struct mkv_cookie const TrackInfo *track_info; + float frame_rate; int64 frame_count; bigtime_t duration; media_format format; + /* bool audio; @@ -206,7 +210,20 @@ mkvReader::SetupVideoCookie(mkv_cookie *cookie) TRACE("video DisplayHeight: %d\n", cookie->track_info->Video.DisplayHeight); TRACE("video ColourSpace: %d\n", cookie->track_info->Video.ColourSpace); TRACE("video GammaValue: %.4f\n", cookie->track_info->Video.GammaValue); - TRACE("video Interlaced: %d\n", cookie->track_info->Video.Interlaced); + + TRACE("video Interlaced: %d\n", cookie->track_info->Video.Interlaced); + + cookie->frame_rate = get_frame_rate(cookie->track_info->DefaultDuration); + cookie->duration = get_duration_in_us(fFileInfo->Duration); + cookie->frame_count = get_frame_count_by_default_duration(fFileInfo->Duration, cookie->track_info->DefaultDuration); + + TRACE("mkvReader::Sniff: TimecodeScale %Ld\n", fFileInfo->TimecodeScale); + TRACE("mkvReader::Sniff: Duration %Ld\n", fFileInfo->Duration); + + TRACE("frame_rate: %.6f\n", cookie->frame_rate); + TRACE("duration: %Ld (%.6f)\n", cookie->duration, cookie->duration / 1E6); + TRACE("frame_count: %Ld\n", cookie->frame_count); + } @@ -217,6 +234,16 @@ mkvReader::SetupAudioCookie(mkv_cookie *cookie) TRACE("audio OutputSamplingFreq: %.3f\n", cookie->track_info->Audio.OutputSamplingFreq); TRACE("audio Channels: %d\n", cookie->track_info->Audio.Channels); TRACE("audio BitDepth: %d\n", cookie->track_info->Audio.BitDepth); + + TRACE("CodecID: %s\n", cookie->track_info->CodecID); + + cookie->frame_rate = cookie->track_info->Audio.SamplingFreq; + cookie->duration = get_duration_in_us(fFileInfo->Duration); + cookie->frame_count = get_frame_count_by_frame_rate(fFileInfo->Duration, cookie->track_info->Audio.SamplingFreq); + + TRACE("frame_rate: %.6f\n", cookie->frame_rate); + TRACE("duration: %Ld (%.6f)\n", cookie->duration, cookie->duration / 1E6); + TRACE("frame_count: %Ld\n", cookie->frame_count); } diff --git a/src/add-ons/media/plugins/matroska/matroska_util.cpp b/src/add-ons/media/plugins/matroska/matroska_util.cpp new file mode 100644 index 0000000000..257a3c097f --- /dev/null +++ b/src/add-ons/media/plugins/matroska/matroska_util.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2004, Marcus Overhagen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include "matroska_util.h" + + +bigtime_t +get_duration_in_us(uint64 duration) +{ + if (duration > 0) + return duration / 1000 + ((duration % 1000) ? 1 : 0); + else + return 12 * 60 * 60 * 1000000LL; +} + + +float +get_frame_rate(uint64 default_duration) +{ + if (default_duration > 1) + return 1000000000.0 / default_duration; + else + return 29.97; +} + + +uint64 +get_frame_count_by_frame_rate(uint64 duration, float frame_rate) +{ + return uint64((double(duration) * double(frame_rate)) / 1000000000.0); +} + + +uint64 +get_frame_count_by_default_duration(uint64 duration, uint64 default_duration) +{ + if (duration > 0 && default_duration > 1) + return (duration / default_duration) + ((duration % default_duration) ? 1 : 0); + if (duration > 0) + return (duration * 2997) / 100000000000ull; + return 12 * 60 * 60 * 2997 / 100; +} diff --git a/src/add-ons/media/plugins/matroska/matroska_util.h b/src/add-ons/media/plugins/matroska/matroska_util.h new file mode 100644 index 0000000000..d446afffb7 --- /dev/null +++ b/src/add-ons/media/plugins/matroska/matroska_util.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2004, Marcus Overhagen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _MATROSKA_UTIL_H +#define _MATROSKA_UTIL_H + +#include + +bigtime_t get_duration_in_us(uint64 duration); +float get_frame_rate(uint64 default_duration); +uint64 get_frame_count_by_frame_rate(uint64 duration, float frame_rate); +uint64 get_frame_count_by_default_duration(uint64 duration, uint64 default_duration); + +#endif +