2003-05-15 08:58:52 +00:00
|
|
|
/*
|
|
|
|
mkvmerge -- utility for splicing together matroska files
|
|
|
|
from component media subtypes
|
|
|
|
|
|
|
|
r_dts.h
|
|
|
|
|
|
|
|
Written by Moritz Bunkus <moritz@bunkus.org>
|
|
|
|
|
|
|
|
Distributed under the GPL
|
|
|
|
see the file COPYING for details
|
|
|
|
or visit http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\file
|
2003-06-15 14:03:28 +00:00
|
|
|
\version $Id$
|
2003-05-15 08:58:52 +00:00
|
|
|
\brief DTS demultiplexer module
|
2003-05-18 20:40:11 +00:00
|
|
|
\author Peter Niemayer <niemayer@isg.de>
|
2003-05-18 20:57:08 +00:00
|
|
|
\author Moritz Bunkus <moritz@bunkus.org>
|
2003-05-15 08:58:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "mkvmerge.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "r_dts.h"
|
|
|
|
#include "p_dts.h"
|
|
|
|
|
2003-05-23 06:34:58 +00:00
|
|
|
int dts_reader_c::probe_file(mm_io_c *mm_io, int64_t size) {
|
2003-05-18 20:40:11 +00:00
|
|
|
char buf[max_dts_packet_size];
|
2003-05-15 08:58:52 +00:00
|
|
|
int pos;
|
|
|
|
dts_header_t dtsheader;
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-18 20:40:11 +00:00
|
|
|
if (size < max_dts_packet_size)
|
2003-05-15 08:58:52 +00:00
|
|
|
return 0;
|
2003-05-23 06:34:58 +00:00
|
|
|
try {
|
|
|
|
mm_io->setFilePointer(0, seek_beginning);
|
|
|
|
if (mm_io->read(buf, max_dts_packet_size) != max_dts_packet_size)
|
|
|
|
return 0;
|
|
|
|
mm_io->setFilePointer(0, seek_beginning);
|
|
|
|
} catch (exception &ex) {
|
2003-05-15 08:58:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-18 20:40:11 +00:00
|
|
|
pos = find_dts_header((unsigned char *)buf, max_dts_packet_size, &dtsheader);
|
2003-05-15 08:58:52 +00:00
|
|
|
if (pos < 0)
|
|
|
|
return 0;
|
2003-05-20 06:30:25 +00:00
|
|
|
|
|
|
|
return 1;
|
2003-05-15 08:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dts_reader_c::dts_reader_c(track_info_t *nti) throw (error_c):
|
|
|
|
generic_reader_c(nti) {
|
|
|
|
int pos;
|
|
|
|
dts_header_t dtsheader;
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-23 06:34:58 +00:00
|
|
|
try {
|
|
|
|
mm_io = new mm_io_c(ti->fname, MODE_READ);
|
|
|
|
mm_io->setFilePointer(0, seek_end);
|
|
|
|
size = mm_io->getFilePointer();
|
|
|
|
mm_io->setFilePointer(0, seek_beginning);
|
|
|
|
chunk = (unsigned char *)safemalloc(max_dts_packet_size);
|
|
|
|
if (mm_io->read(chunk, max_dts_packet_size) != max_dts_packet_size)
|
|
|
|
throw error_c("dts_reader: Could not read max_dts_packet_size bytes.");
|
|
|
|
mm_io->setFilePointer(0, seek_beginning);
|
|
|
|
} catch (exception &ex) {
|
|
|
|
throw error_c("dts_reader: Could not open the source file.");
|
|
|
|
}
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-18 20:40:11 +00:00
|
|
|
pos = find_dts_header(chunk, max_dts_packet_size, &dtsheader);
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-15 08:58:52 +00:00
|
|
|
if (pos < 0)
|
2003-05-18 20:40:11 +00:00
|
|
|
throw error_c("dts_reader: No valid DTS packet found in the first "
|
|
|
|
"max_dts_packet_size bytes.\n");
|
2003-05-15 08:58:52 +00:00
|
|
|
bytes_processed = 0;
|
2003-06-15 10:03:09 +00:00
|
|
|
ti->id = 0; // ID for this track.
|
2003-05-18 20:40:11 +00:00
|
|
|
dtspacketizer = new dts_packetizer_c(this, dtsheader, ti);
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-18 20:40:11 +00:00
|
|
|
if (verbose) {
|
|
|
|
fprintf(stdout, "Using DTS demultiplexer for %s.\n+-> Using "
|
2003-05-15 08:58:52 +00:00
|
|
|
"DTS output module for audio stream.\n", ti->fname);
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-18 20:40:11 +00:00
|
|
|
print_dts_header(&dtsheader);
|
|
|
|
}
|
2003-05-15 08:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dts_reader_c::~dts_reader_c() {
|
2003-05-23 06:34:58 +00:00
|
|
|
delete mm_io;
|
2003-05-15 08:58:52 +00:00
|
|
|
safefree(chunk);
|
|
|
|
if (dtspacketizer != NULL)
|
|
|
|
delete dtspacketizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dts_reader_c::read() {
|
|
|
|
int nread;
|
2003-05-20 06:30:25 +00:00
|
|
|
|
2003-05-23 06:34:58 +00:00
|
|
|
nread = mm_io->read(chunk, max_dts_packet_size);
|
2003-05-15 08:58:52 +00:00
|
|
|
if (nread <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dtspacketizer->process(chunk, nread);
|
|
|
|
bytes_processed += nread;
|
|
|
|
|
|
|
|
return EMOREDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
packet_t *dts_reader_c::get_packet() {
|
|
|
|
return dtspacketizer->get_packet();
|
|
|
|
}
|
|
|
|
|
|
|
|
int dts_reader_c::display_priority() {
|
|
|
|
return DISPLAYPRIORITY_HIGH - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dts_reader_c::display_progress() {
|
|
|
|
fprintf(stdout, "progress: %lld/%lld bytes (%d%%)\r",
|
|
|
|
bytes_processed, size,
|
|
|
|
(int)(bytes_processed * 100L / size));
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dts_reader_c::set_headers() {
|
|
|
|
dtspacketizer->set_headers();
|
|
|
|
}
|
2003-06-12 23:05:49 +00:00
|
|
|
|
|
|
|
void dts_reader_c::identify() {
|
|
|
|
fprintf(stdout, "File '%s': container: DTS\nTrack ID 0: audio (DTS)\n",
|
|
|
|
ti->fname);
|
|
|
|
}
|