Skip to content

Commit

Permalink
Initial import of Ahab 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Feb 25, 2010
0 parents commit e2ac788
Show file tree
Hide file tree
Showing 51 changed files with 9,270 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Makefile
@@ -0,0 +1,27 @@
source = ahab.cpp es.cpp mpegheader.cpp bitreader.cpp startfinder.cpp sequence.cpp extensions.cpp exceptions.cpp picture.cpp slice.cpp file.cpp ogl.cpp slicedecode.cpp idct_mmx.cpp motion_comp_mmx.cpp framebuffer.cpp opq.cpp displayop.cpp controller.cpp displayopq.cpp decoder.cpp decoderop.cpp decoderopq.cpp xeventloop.cpp
objects = es.o mpegheader.o bitreader.o startfinder.o sequence.o extensions.o exceptions.o picture.o slice.o file.o ogl.o slicedecode.o idct_mmx.o motion_comp_mmx.o framebuffer.o opq.o displayop.o controller.o displayopq.o decoder.o decoderop.o decoderopq.o xeventloop.o
executables = ahab

CPP = g++
CPPFLAGS = -g -O3 -Wall -fno-implicit-templates -pipe -pthread -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500 -DGL_GLEXT_PROTOTYPES -DGLX_GLXEXT_PROTOTYPES `pkg-config gtkmm-2.4 --cflags`
LIBS = -lX11 -lGL -lGLU `pkg-config gtkmm-2.4 --libs`

all: $(executables)

controller.o: controller.cpp
$(CPP) $(CPPFLAGS) -frepo -c -o $@ $<

ahab: ahab.o $(objects)
$(CPP) $(CPPFLAGS) -o $@ $+ $(LIBS)

%.o: %.cpp
$(CPP) $(CPPFLAGS) -c -o $@ $<

include depend

depend: $(source)
$(CPP) $(INCLUDES) -MM $(source) > depend

.PHONY: clean
clean:
-rm -f $(executables) depend *.o *.rpo
109 changes: 109 additions & 0 deletions ahab.cpp
@@ -0,0 +1,109 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "libmpeg2.h"

#include "controller.hpp"
#include "file.hpp"
#include "es.hpp"
#include "ogl.hpp"
#include "framebuffer.hpp"
#include "colorimetry.hpp"
#include "decoder.hpp"
#include "xeventloop.hpp"

#include <sys/time.h>
#include <math.h>

void progress_bar( off_t size, off_t location );

int main( int argc, char *argv[] )
{
File *file;
ES *stream;
Sequence *seq;
OpenGLDisplay *display;
Controller *controller;
Decoder *decoder;
XEventLoop *xevents;

if ( argc != 2 ) {
fprintf( stderr, "USAGE: %s FILENAME\n", argv[ 0 ] );
exit( 1 );
}

fprintf( stderr, "Opening file..." );
file = new File( argv[ 1 ] );
fprintf( stderr, " done.\n" );

fprintf( stderr, "Constructing elementary stream object... " );
try {
stream = new ES( file, &progress_bar );
} catch ( AhabException *e ) {
fprintf( stderr, "Caught exception.\n" );
if ( UnixError *ue = dynamic_cast<UnixError *>( e ) ) {
fprintf( stderr, "UnixError( %d )\n", ue->err );
}
return 1;
}

fprintf( stderr, "\b\b\b\b\b\b\b done. \n" );

seq = stream->get_sequence();

display = new OpenGLDisplay( (char *)NULL, seq->get_sar(),
16 * seq->get_mb_width(),
16 * seq->get_mb_height(),
seq->get_horizontal_size(),
seq->get_vertical_size() );

fprintf( stderr, "Pictures: %d, duration: %.3f seconds.\n",
stream->get_num_pictures(), stream->get_duration() );

controller = new Controller( stream->get_num_pictures() );

decoder = new Decoder( stream, display->get_queue() );

xevents = new XEventLoop( display );

controller->get_queue()->hookup( decoder->get_queue() );
xevents->get_queue()->hookup( decoder->get_queue() );

try {
decoder->wait_shutdown();
} catch ( UnixAssertError *e ) {
e->print();
}

try {
delete xevents;
delete decoder;
delete controller;
delete display;
delete stream;
delete file;
} catch ( UnixAssertError *e ) {
e->print();
}

return 0;
}

void progress_bar( off_t size, off_t location )
{
static char percent[ 20 ] = "";
char new_percent[ 20 ] = "";
char backspaces[ 6 ] = "\b\b\b\b\b";

snprintf( new_percent, 20, "%2.0f", 100.0 * location / (double)size );

if ( (percent[ 1 ] != new_percent[ 1 ])
|| (percent[ 0 ] != new_percent[ 0 ]) ) {
fprintf( stderr, "%s[%s%%]", backspaces, new_percent );
}

percent[ 0 ] = new_percent[ 0 ];
percent[ 1 ] = new_percent[ 1 ];
}
52 changes: 52 additions & 0 deletions ahab_fragment_program.hpp
@@ -0,0 +1,52 @@
#ifndef AHAB_FRAGMENT_PROGRAM_HPP
#define AHAB_FRAGMENT_PROGRAM_HPP

/*
Matlab inversion of BT.709 matrix:
>> 255 * inv([219*[.7154 .0721 .2125]' 224*[-.386 .5 -.115]' 224*[-.454 -.046 .5]']')
ans =
1.164165557121523 -0.213138349939461 -0.532748200973066
1.166544220758321 2.112430116393991 0.001144179685436
1.164384394176109 0.000813948963217 1.793155612333230
*/

/* Matrix inverstion of SMPTE 170M matrix:
>> 255 * inv([219*[.587 .114 .299]' 224*[-.331 .500 -.169]' 224*[-.419 -.081 .5]']')
ans =
1.164383561643836 -0.391260370716072 -0.813004933873461
1.164383561643836 2.017414758970775 0.001127259960693
1.164383561643836 -0.001054999706803 1.595670195813386
*/

static char ahab_fragment_program[] = {
"!!ARBfp1.0\n"

"ATTRIB where_Y = fragment.texcoord[0];\n"
"ATTRIB where_Cb = fragment.texcoord[1];\n"
"ATTRIB where_Cr = fragment.texcoord[2];\n"
"OUTPUT out = result.color;\n"

"TEMP YPBPR;\n"

"TEX YPBPR.x, where_Y, texture[0], RECT;\n"
"TEX YPBPR.y, where_Cb, texture[1], RECT;\n"
"TEX YPBPR.z, where_Cr, texture[2], RECT;\n"

"PARAM CTOP = { .06274509803921568627, .50196078431372549019, .50196078431372549019 };\n"

"SUB YPBPR, YPBPR, CTOP;\n"

"DP3 out.g, YPBPR, program.local[ 0 ];\n"
"DP3 out.b, YPBPR, program.local[ 1 ];\n"
"DP3 out.r, YPBPR, program.local[ 2 ];\n"

"END\n"
};

#endif
42 changes: 42 additions & 0 deletions attributes.h
@@ -0,0 +1,42 @@
/*
* attributes.h
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
* See http://libmpeg2.sourceforge.net/ for updates.
*
* mpeg2dec is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* mpeg2dec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef LIBMPEG2_ATTRIBUTES_H
#define LIBMPEG2_ATTRIBUTES_H

/* use gcc attribs to align critical data structures */
#ifdef ATTRIBUTE_ALIGNED_MAX
#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
#else
#define ATTR_ALIGN(align)
#endif

#ifdef HAVE_BUILTIN_EXPECT
#define likely(x) __builtin_expect ((x) != 0, 1)
#define unlikely(x) __builtin_expect ((x) != 0, 0)
#else
#define likely(x) (x)
#define unlikely(x) (x)
#endif

#endif /* LIBMPEG2_ATTRIBUTES_H */
30 changes: 30 additions & 0 deletions bitreader.cpp
@@ -0,0 +1,30 @@
#include <stdint.h>
#include <stdio.h>

#include "bitreader.hpp"
#include "exceptions.hpp"

inline bool BitReader::thisbit( void )
{
uint octet = bit_offset / 8;
uint offset_within_octet = 7 - (bit_offset % 8);

return ( buf[ octet ] & (1 << offset_within_octet) ? true : false );
}

uint32_t BitReader::readbits( uint n )
{
uint32_t val = 0;

if ( (bit_offset + n - 1)/8 >= len ) {
throw NeedBits();
}

for ( uint i = 0; i < n; i++ ) {
val <<= 1;
val |= thisbit();
bit_offset++;
}

return val;
}
27 changes: 27 additions & 0 deletions bitreader.hpp
@@ -0,0 +1,27 @@
#ifndef BITREADER_HPP
#define BITREADER_HPP

#include <stdint.h>
#include <stdlib.h>

class BitReader {
private:
uint8_t *buf;
uint len;

uint bit_offset;

bool thisbit( void );

public:
BitReader( uint8_t *s_buf, uint s_len ) {
buf = s_buf;
bit_offset = 0;
len = s_len;
}

uint32_t readbits( uint n );
void reset( void ) { bit_offset = 0; }
};

#endif
17 changes: 17 additions & 0 deletions colorimetry.hpp
@@ -0,0 +1,17 @@
#ifndef COLORIMETRY_HPP
#define COLORIMETRY_HPP

#include "displayop.hpp"

static double smpte170m_green[ 3 ] = { 1.164383561643836, -0.391260370716072, -0.813004933873461 };
static double smpte170m_blue[ 3 ] = { 1.164383561643836, 2.017414758970775, 0.001127259960693 };
static double smpte170m_red[ 3 ] = { 1.164383561643836, -0.001054999706803, 1.595670195813386 };

static double itu709_green[ 3 ] = { 1.164165557121523, -0.213138349939461, -0.532748200973066 };
static double itu709_blue[ 3 ] = { 1.166544220758321, 2.112430116393991, 0.001144179685436 };
static double itu709_red[ 3 ] = { 1.164384394176109, 0.000813948963217, 1.793155612333230 };

static LoadMatrixCoefficients smpte170m( smpte170m_green, smpte170m_blue, smpte170m_red );
static LoadMatrixCoefficients itu709( itu709_green, itu709_blue, itu709_red );

#endif

0 comments on commit e2ac788

Please sign in to comment.