calculate duration and an approximation of frame rate and frame count

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9827 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2004-11-07 14:46:05 +00:00
parent b1158dce78
commit 1841471ea4
6 changed files with 192 additions and 1 deletions
@@ -6,7 +6,9 @@ UsePrivateHeaders media ;
SubDirHdrs [ FDirName $(SUBDIR) libMatroskaParser ] ;
Addon matroska : media plugins :
matroska_codecs.cpp
matroska_reader.cpp
matroska_util.cpp
:
false
:
@@ -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 <stdio.h>
#include <string.h>
#include <malloc.h>
#include <DataIO.h>
#include <ByteOrder.h>
#include <InterfaceDefs.h>
#include <MediaFormats.h>
#include "RawFormats.h"
#include "matroska_reader.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
@@ -31,6 +31,8 @@
#include <MediaFormats.h>
#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);
}
@@ -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 <string.h>
#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;
}
@@ -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 <SupportDefs.h>
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