2009-04-06 21:14:55 +02:00
|
|
|
// Copyright (c) 2007-2009 Fredrik Mellbin
|
2008-09-01 23:16:13 +02:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
2009-04-24 21:56:19 +02:00
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
}
|
|
|
|
|
2008-09-01 23:16:13 +02:00
|
|
|
#include "ffms.h"
|
|
|
|
#include "ffvideosource.h"
|
2008-09-19 23:35:46 +02:00
|
|
|
#include "ffaudiosource.h"
|
2008-09-01 23:16:13 +02:00
|
|
|
#include "indexing.h"
|
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#ifdef __UNIX__
|
|
|
|
#define _snprintf snprintf
|
|
|
|
#endif
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
TFrameInfo::TFrameInfo(int64_t DTS, bool KeyFrame) {
|
2008-09-27 03:21:57 +02:00
|
|
|
this->DTS = DTS;
|
|
|
|
this->SampleStart = 0;
|
|
|
|
this->FilePos = 0;
|
|
|
|
this->FrameSize = 0;
|
|
|
|
this->KeyFrame = KeyFrame;
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
TFrameInfo::TFrameInfo(int64_t DTS, int64_t SampleStart, bool KeyFrame) {
|
2008-09-27 03:21:57 +02:00
|
|
|
this->DTS = DTS;
|
|
|
|
this->SampleStart = SampleStart;
|
|
|
|
this->FilePos = 0;
|
|
|
|
this->FrameSize = 0;
|
|
|
|
this->KeyFrame = KeyFrame;
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
TFrameInfo::TFrameInfo(int64_t SampleStart, int64_t FilePos, unsigned int FrameSize, bool KeyFrame) {
|
2008-09-27 03:21:57 +02:00
|
|
|
this->DTS = 0;
|
|
|
|
this->SampleStart = SampleStart;
|
|
|
|
this->FilePos = FilePos;
|
|
|
|
this->FrameSize = FrameSize;
|
|
|
|
this->KeyFrame = KeyFrame;
|
|
|
|
}
|
|
|
|
|
2008-09-02 01:18:50 +02:00
|
|
|
FFMS_API(void) FFMS_Init() {
|
|
|
|
static bool InitDone = false;
|
2009-05-12 22:50:40 +02:00
|
|
|
if (!InitDone) {
|
2008-09-02 01:18:50 +02:00
|
|
|
av_register_all();
|
2009-05-12 22:50:40 +02:00
|
|
|
av_log_set_level(AV_LOG_QUIET);
|
|
|
|
}
|
2008-09-02 01:18:50 +02:00
|
|
|
InitDone = true;
|
|
|
|
}
|
2009-01-03 16:17:53 +01:00
|
|
|
|
2009-05-12 22:50:40 +02:00
|
|
|
FFMS_API(int) FFMS_GetLogLevel() {
|
|
|
|
return av_log_get_level();
|
|
|
|
}
|
|
|
|
|
|
|
|
FFMS_API(void) FFMS_SetLogLevel(int Level) {
|
2009-01-03 16:17:53 +01:00
|
|
|
av_log_set_level(AV_LOG_QUIET);
|
|
|
|
}
|
2008-09-02 01:18:50 +02:00
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(FFVideo *) FFMS_CreateVideoSource(const char *SourceFile, int Track, FFIndex *Index, const char *PP, int Threads, int SeekMode, char *ErrorMsg, unsigned MsgSize) {
|
2008-09-23 21:25:34 +02:00
|
|
|
try {
|
2009-05-16 01:11:18 +02:00
|
|
|
switch (Index->Decoder) {
|
|
|
|
case 0: return new FFVideoSource(SourceFile, Track, Index, PP, Threads, SeekMode, ErrorMsg, MsgSize);
|
|
|
|
case 1: return new MatroskaVideoSource(SourceFile, Track, Index, PP, Threads, ErrorMsg, MsgSize);
|
2009-04-11 20:45:40 +02:00
|
|
|
#ifdef HAALISOURCE
|
2009-05-16 01:11:18 +02:00
|
|
|
case 2: return new HaaliVideoSource(SourceFile, Track, Index, PP, Threads, 0, ErrorMsg, MsgSize);
|
|
|
|
case 3: return new HaaliVideoSource(SourceFile, Track, Index, PP, Threads, 1, ErrorMsg, MsgSize);
|
2008-12-31 01:06:57 +01:00
|
|
|
#endif
|
2008-09-23 21:51:19 +02:00
|
|
|
default:
|
|
|
|
_snprintf(ErrorMsg, MsgSize, "Unsupported format");
|
|
|
|
return NULL;
|
2008-09-23 21:25:34 +02:00
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
return NULL;
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(FFAudio *) FFMS_CreateAudioSource(const char *SourceFile, int Track, FFIndex *Index, char *ErrorMsg, unsigned MsgSize) {
|
2008-09-23 21:25:34 +02:00
|
|
|
try {
|
2009-05-16 01:11:18 +02:00
|
|
|
switch (Index->Decoder) {
|
|
|
|
case 0: return new FFAudioSource(SourceFile, Track, Index, ErrorMsg, MsgSize);
|
|
|
|
case 1: return new MatroskaAudioSource(SourceFile, Track, Index, ErrorMsg, MsgSize);
|
2008-09-23 21:51:19 +02:00
|
|
|
default:
|
|
|
|
_snprintf(ErrorMsg, MsgSize, "Unsupported format");
|
|
|
|
return NULL;
|
2008-09-23 21:25:34 +02:00
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
return NULL;
|
2008-09-19 23:35:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(void) FFMS_DestroyVideoSource(FFVideo *V) {
|
|
|
|
delete V;
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(void) FFMS_DestroyAudioSource(FFAudio *A) {
|
|
|
|
delete A;
|
2008-09-19 23:35:46 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(const TVideoProperties *) FFMS_GetTVideoProperties(FFVideo *V) {
|
|
|
|
return &V->GetTVideoProperties();
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(const TAudioProperties *) FFMS_GetTAudioProperties(FFAudio *A) {
|
|
|
|
return &A->GetTAudioProperties();
|
2008-09-19 23:35:46 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(const TAVFrameLite *) FFMS_GetFrame(FFVideo *V, int n, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
return (TAVFrameLite *)V->GetFrame(n, ErrorMsg, MsgSize);
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(const TAVFrameLite *) FFMS_GetFrameByTime(FFVideo *V, double Time, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
return (TAVFrameLite *)V->GetFrameByTime(Time, ErrorMsg, MsgSize);
|
2008-09-27 03:21:57 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_GetAudio(FFAudio *A, void *Buf, int64_t Start, int64_t Count, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
return A->GetAudio(Buf, Start, Count, ErrorMsg, MsgSize);
|
2008-09-19 23:35:46 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_SetOutputFormat(FFVideo *V, int TargetFormat, int Width, int Height, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
return V->SetOutputFormat(TargetFormat, Width, Height, ErrorMsg, MsgSize);
|
2008-09-09 22:49:59 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(void) FFMS_ResetOutputFormat(FFVideo *V) {
|
|
|
|
V->ResetOutputFormat();
|
2008-09-09 22:49:59 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(void) FFMS_DestroyFFIndex(FFIndex *Index) {
|
|
|
|
delete Index;
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_GetFirstTrackOfType(FFIndex *Index, int TrackType, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
for (int i = 0; i < static_cast<int>(Index->size()); i++)
|
|
|
|
if ((*Index)[i].TT == TrackType)
|
2008-09-27 21:05:10 +02:00
|
|
|
return i;
|
|
|
|
_snprintf(ErrorMsg, MsgSize, "No suitable track found");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_GetNumTracks(FFIndex *Index) {
|
|
|
|
return Index->size();
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_GetTrackType(FFTrack *T) {
|
|
|
|
return T->TT;
|
2008-09-23 23:56:30 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_GetNumFrames(FFTrack *T) {
|
|
|
|
return T->size();
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(const TFrameInfo *) FFMS_GetTFrameInfo(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
if (Frame < 0 || Frame >= static_cast<int>(T->size())) {
|
2008-09-01 23:16:13 +02:00
|
|
|
_snprintf(ErrorMsg, MsgSize, "Invalid frame specified");
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2009-05-16 01:11:18 +02:00
|
|
|
return &(*T)[Frame];
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(FFTrack *) FFMS_GetTITrackIndex(FFIndex *Index, int Track, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
if (Track < 0 || Track >= static_cast<int>(Index->size())) {
|
2008-09-01 23:16:13 +02:00
|
|
|
_snprintf(ErrorMsg, MsgSize, "Invalid track specified");
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2009-05-16 01:11:18 +02:00
|
|
|
return &(*Index)[Track];
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(FFTrack *) FFMS_GetVSTrackIndex(FFVideo *V) {
|
|
|
|
return V->GetFFTrack();
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_FindClosestKeyFrame(FFTrack *T, int Frame, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
if (Frame < 0 || Frame >= static_cast<int>(T->size())) {
|
2008-09-01 23:16:13 +02:00
|
|
|
_snprintf(ErrorMsg, MsgSize, "Out of range frame specified");
|
|
|
|
return -1;
|
|
|
|
} else {
|
2009-05-16 01:11:18 +02:00
|
|
|
return T->FindClosestKeyFrame(Frame);
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(const TTrackTimeBase *) FFMS_GetTimeBase(FFTrack *T) {
|
|
|
|
return &T->TB;
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_WriteTimecodes(FFTrack *T, const char *TimecodeFile, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
return T->WriteTimecodes(TimecodeFile, ErrorMsg, MsgSize);
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(FFIndex *) FFMS_MakeIndex(const char *SourceFile, int IndexMask, int DumpMask, const char *AudioFile, bool IgnoreDecodeErrors, TIndexCallback IP, void *Private, char *ErrorMsg, unsigned MsgSize) {
|
2008-09-24 16:11:45 +02:00
|
|
|
return MakeIndex(SourceFile, IndexMask, DumpMask, AudioFile, IgnoreDecodeErrors, IP, Private, ErrorMsg, MsgSize);
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(FFIndex *) FFMS_ReadIndex(const char *IndexFile, char *ErrorMsg, unsigned MsgSize) {
|
2008-09-04 00:26:27 +02:00
|
|
|
return ReadIndex(IndexFile, ErrorMsg, MsgSize);
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-05-16 01:11:18 +02:00
|
|
|
FFMS_API(int) FFMS_WriteIndex(const char *IndexFile, FFIndex *Index, char *ErrorMsg, unsigned MsgSize) {
|
|
|
|
return WriteIndex(IndexFile, Index, ErrorMsg, MsgSize);
|
2008-09-01 23:16:13 +02:00
|
|
|
}
|
|
|
|
|
2009-04-25 10:55:14 +02:00
|
|
|
FFMS_API(int) FFMS_GetPixFmt(const char *Name) {
|
2009-04-24 21:56:19 +02:00
|
|
|
return avcodec_get_pix_fmt(Name);
|
2009-04-29 18:39:15 +02:00
|
|
|
}
|
2009-05-16 01:11:18 +02:00
|
|
|
|
|
|
|
FFMS_API(int) FFMS_DefaultAudioName(const char *SourceFile, int Track, const TAudioProperties *AP, char *FileName, unsigned FNSize) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|