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.
|
|
|
|
|
|
|
|
#ifndef INDEXING_H
|
|
|
|
#define INDEXING_H
|
|
|
|
|
|
|
|
#include "utils.h"
|
2009-05-22 23:28:02 +02:00
|
|
|
#include "wave64writer.h"
|
2008-09-01 23:16:13 +02:00
|
|
|
|
2009-05-23 16:18:51 +02:00
|
|
|
#define INDEXVERSION 26
|
2008-09-01 23:16:13 +02:00
|
|
|
#define INDEXID 0x53920873
|
|
|
|
|
|
|
|
struct IndexHeader {
|
|
|
|
uint32_t Id;
|
|
|
|
uint32_t Version;
|
|
|
|
uint32_t Tracks;
|
|
|
|
uint32_t Decoder;
|
2009-05-18 00:02:43 +02:00
|
|
|
uint32_t LAVUVersion;
|
|
|
|
uint32_t LAVFVersion;
|
|
|
|
uint32_t LAVCVersion;
|
|
|
|
uint32_t LSWSVersion;
|
|
|
|
uint32_t LPPVersion;
|
2008-09-01 23:16:13 +02:00
|
|
|
};
|
|
|
|
|
2009-05-22 23:28:02 +02:00
|
|
|
class SharedAudioContext {
|
|
|
|
public:
|
|
|
|
Wave64Writer *W64W;
|
|
|
|
AVCodecContext *CTX;
|
|
|
|
int64_t CurrentSample;
|
|
|
|
|
|
|
|
SharedAudioContext() {
|
|
|
|
W64W = NULL;
|
|
|
|
CTX = NULL;
|
|
|
|
CurrentSample = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~SharedAudioContext() {
|
|
|
|
delete W64W;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-20 20:57:03 +02:00
|
|
|
class FFIndexer {
|
|
|
|
protected:
|
|
|
|
int IndexMask;
|
|
|
|
int DumpMask;
|
|
|
|
bool IgnoreDecodeErrors;
|
|
|
|
TIndexCallback IC;
|
2009-05-22 23:28:02 +02:00
|
|
|
void *ICPrivate;
|
|
|
|
TAudioNameCallback ANC;
|
|
|
|
void *ANCPrivate;
|
|
|
|
const char *SourceFile;
|
2009-05-23 01:28:08 +02:00
|
|
|
int16_t *DecodingBuffer;
|
2009-05-22 23:28:02 +02:00
|
|
|
|
|
|
|
bool WriteAudio(SharedAudioContext &AudioContext, FFIndex *Index, int Track, int DBSize, char *ErrorMsg, unsigned MsgSize);
|
2009-05-18 00:02:43 +02:00
|
|
|
public:
|
2009-05-20 20:57:03 +02:00
|
|
|
static FFIndexer *CreateFFIndexer(const char *Filename, char *ErrorMsg, unsigned MsgSize);
|
2009-05-23 16:18:51 +02:00
|
|
|
FFIndexer();
|
|
|
|
virtual ~FFIndexer();
|
2009-05-20 20:57:03 +02:00
|
|
|
void SetIndexMask(int IndexMask) { this->IndexMask = IndexMask; }
|
|
|
|
void SetDumpMask(int DumpMask) { this->DumpMask = DumpMask; }
|
|
|
|
void SetIgnoreDecodeErrors(bool IgnoreDecodeErrors) { this->IgnoreDecodeErrors = IgnoreDecodeErrors; }
|
2009-05-22 23:28:02 +02:00
|
|
|
void SetProgressCallback(TIndexCallback IC, void *ICPrivate) { this->IC = IC; this->ICPrivate = ICPrivate; }
|
|
|
|
void SetAudioNameCallback(TAudioNameCallback ANC, void *ANCPrivate) { this->ANC = ANC; this->ANCPrivate = ANCPrivate; }
|
|
|
|
virtual FFIndex *DoIndexing(char *ErrorMsg, unsigned MsgSize) = 0;
|
2009-05-20 20:57:03 +02:00
|
|
|
virtual int GetNumberOfTracks() = 0;
|
|
|
|
virtual FFMS_TrackType GetTrackType(int Track) = 0;
|
|
|
|
virtual const char *GetTrackCodec(int Track) = 0;
|
|
|
|
};
|
2008-09-01 23:16:13 +02:00
|
|
|
|
2009-05-20 20:57:03 +02:00
|
|
|
class FFLAVFIndexer : public FFIndexer {
|
|
|
|
private:
|
|
|
|
bool IsIndexing;
|
|
|
|
AVFormatContext *FormatContext;
|
|
|
|
public:
|
2009-05-22 23:28:02 +02:00
|
|
|
FFLAVFIndexer(const char *Filename, AVFormatContext *FormatContext, char *ErrorMsg, unsigned MsgSize);
|
2009-05-20 20:57:03 +02:00
|
|
|
~FFLAVFIndexer();
|
2009-05-22 23:28:02 +02:00
|
|
|
FFIndex *DoIndexing(char *ErrorMsg, unsigned MsgSize);
|
2009-05-20 20:57:03 +02:00
|
|
|
int GetNumberOfTracks() { return FormatContext->nb_streams; }
|
|
|
|
FFMS_TrackType GetTrackType(int Track) { return static_cast<FFMS_TrackType>(FormatContext->streams[Track]->codec->codec_type); }
|
2009-05-23 22:04:38 +02:00
|
|
|
const char *GetTrackCodec(int Track) {
|
|
|
|
return (avcodec_find_decoder(FormatContext->streams[Track]->codec->codec_id))->long_name;
|
|
|
|
}
|
2008-09-01 23:16:13 +02:00
|
|
|
};
|
|
|
|
|
2009-05-20 20:57:03 +02:00
|
|
|
class FFMatroskaIndexer : public FFIndexer {
|
|
|
|
private:
|
|
|
|
MatroskaFile *MF;
|
|
|
|
MatroskaReaderContext MC;
|
2009-05-23 22:04:38 +02:00
|
|
|
AVCodec *Codec[32];
|
2009-05-18 00:02:43 +02:00
|
|
|
public:
|
2009-05-20 20:57:03 +02:00
|
|
|
FFMatroskaIndexer(const char *Filename, char *ErrorMsg, unsigned MsgSize);
|
2009-05-22 23:28:02 +02:00
|
|
|
FFIndex *DoIndexing(char *ErrorMsg, unsigned MsgSize);
|
2009-05-20 20:57:03 +02:00
|
|
|
int GetNumberOfTracks() { return mkv_GetNumTracks(MF); }
|
|
|
|
FFMS_TrackType GetTrackType(int Track) { return HaaliTrackTypeToFFTrackType(mkv_GetTrackInfo(MF, Track)->Type); }
|
2009-05-23 22:04:38 +02:00
|
|
|
const char *GetTrackCodec(int Track) { if (Codec[Track]) return Codec[Track]->long_name; else return "Unsupported codec/Unknown codec name"; }
|
2008-09-01 23:16:13 +02:00
|
|
|
};
|
|
|
|
|
2009-05-20 21:05:42 +02:00
|
|
|
#ifdef HAALISOURCE
|
|
|
|
|
2009-05-20 20:57:03 +02:00
|
|
|
class FFHaaliIndexer : public FFIndexer {
|
|
|
|
private:
|
|
|
|
int SourceMode;
|
|
|
|
CComPtr<IMMContainer> pMMC;
|
|
|
|
int NumTracks;
|
|
|
|
FFMS_TrackType TrackType[32];
|
|
|
|
AVCodec *Codec[32];
|
|
|
|
uint8_t *CodecPrivate[32];
|
|
|
|
int CodecPrivateSize[32];
|
|
|
|
public:
|
|
|
|
FFHaaliIndexer(const char *Filename, int SourceMode, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
~FFHaaliIndexer() { for (int i = 0; i < 32; i++) delete[] CodecPrivate[i]; }
|
2009-05-22 23:28:02 +02:00
|
|
|
FFIndex *DoIndexing(char *ErrorMsg, unsigned MsgSize);
|
2009-05-20 20:57:03 +02:00
|
|
|
int GetNumberOfTracks() { return NumTracks; }
|
|
|
|
FFMS_TrackType GetTrackType(int Track) { return TrackType[Track]; }
|
2009-05-23 22:04:38 +02:00
|
|
|
const char *GetTrackCodec(int Track) { if (Codec[Track]) return Codec[Track]->long_name; else return "Unsupported codec/Unknown codec name"; }
|
2009-05-20 20:57:03 +02:00
|
|
|
};
|
2008-09-01 23:16:13 +02:00
|
|
|
|
2009-05-20 21:05:42 +02:00
|
|
|
#endif // HAALISOURCE
|
|
|
|
|
2008-09-01 23:16:13 +02:00
|
|
|
#endif
|