Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
astream.cc
Package: dvd-munitions.tar.gz [view]
Upload User: aoeyumen
Upload Date: 2007-01-06
Package Size: 3329k
Code Size: 2k
Category:
DVD
Development Platform:
Unix_Linux
- /*
- File: astream.cc
- By: Alex Theo de Jong
- Created: February 1996
- */
- #include <stdio.h>
- #include <fstream.h>
- #include <sys/time.h>
- #include <unistd.h>
- #include "athread.hh"
- #include "error.hh"
- #include "debug.hh"
- #include "util.hh"
- #include "sync.hh"
- #include "mpeg2const.hh"
- #include "mpeg2buff.hh"
- #include "astream.hh"
- /*
- *
- * AudioStream
- *
- */
- AudioStream::AudioStream(const char *filename) :
- word(0), frames(0), bitindex(0), file(True), bytes(0)
- {
- inputstream=new Mpeg2Input(filename, 8196);
- sync=0;
- }
- AudioStream::AudioStream(Mpeg2Buffer* input, Synchronization* s) :
- word(0), frames(0), bitindex(0), file(False), bytes(0)
- {
- if (!(inputstream=input)){
- error("no audio input buffer");
- athr_exit(0);
- }
- sync=s;
- }
- AudioStream::~AudioStream(void){
- if (inputstream) inputstream->close();
- if (file) delete inputstream;
- }
- #if DEBUG
- unsigned int AudioStream::get_bits(int n){
- for (; bytes && bitindex <= 24; bitindex += 8, bytes--)
- word|=(inputstream->getbyte() << (24 - bitindex));
- value=0;
- value=(word >> (32-n));
- bitindex-=n;
- word<<=n;
- return value;
- }
- bool AudioStream::get_header(unsigned int& headerstring){
- TRACER("bool AudioStream::get_header(unsigned int& headerstring)");
- if (bytes) inputstream->skipbytes(bytes);
- if (sync) sync->usedbytes(2, 4); // 2 is audio ID, 4 is number of bytes
- if (inputstream->waitforbytes(4)!=4){
- TRACER("audio stream failed - exit");
- athr_exit(0);
- return False;
- }
- headerstring=inputstream->getbits32();
- inputstream->signal_buffer();
- while (((headerstring & 0xfff00000)!=0xfff00000) ){
- // In search mode for next header
- if (inputstream->waitforbytes(1)!=1){
- TRACER("audio stream failed - exit");
- athr_exit(0);
- return False;
- }
- headerstring<<=8;
- headerstring|=(inputstream->getbyte() & 0x000000ff);
- inputstream->signal_buffer();
- }
- return (headerstring) ? True : False;
- }
- bool AudioStream::read_frame(int bytesize){
- if ((bytes=inputstream->waitforbytes(bytesize))!=bytesize){
- TRACER("audio stream failed - exit");
- athr_exit(0);
- return False;
- }
- if (sync) sync->usedbytes(2, bytesize); // 2 is audio ID, bytesize is number of bytes
- frames++;
- bitindex=0;
- return True;
- }
- #endif