Browse files

Not further development plans with it.

  • Loading branch information...
1 parent 97e051c commit b873f6aee214dffb18584e5f47f83445c5c40c25 huceke committed Aug 24, 2010
View
31 test_interlaced/Makefile
@@ -1,31 +0,0 @@
-XINEPLUGIN = xineplug_decode_crystalhd.so
-
-INSTALL = install
-XINEPLUGINDIR = $(shell pkg-config --variable=plugindir libxine)
-
-CFLAGS = -O2 -march=amdfam10 -msse2 -mssse3 -mfpmath=sse -fomit-frame-pointer -pipe -DNOVDPAU -fPIC -Wall -Werror
-CFLAGS += $(shell pkg-config --cflags libxine) -I/usr/include/libcrystalhd
-LIBS += $(shell pkg-config --libs libxine) -lcrystalhd
-LDFLAGS = -shared -fvisibility=hidden -g -fPIC
-
-CFLAGS += -DEXPORTED=__attribute__\(\(visibility\(\"default\"\)\)\)
-
-OBJ = cpb.o nal.o h264_parser.o crystalhd.o crystalhd_hw.o crystalhd_h264.o crystalhd_vc1.o
-
-all: clean $(XINEPLUGIN)
-
-$(XINEPLUGIN): $(OBJ)
- $(CC) $(LDFLAGS) $(LIBS) $(OBJ) -o $@
-
-.c: %.o
- $(CC) $(CFLAGS) $< -o $@
-
-install: all
- @echo Installing $(XINEPLUGINDIR)/$(XINEPLUGIN)
- @-rm -rf $(XINEPLUGINDIR)/*crystalhd*
- @$(INSTALL) -D -m 0755 $(XINEPLUGIN) $(XINEPLUGINDIR)/$(XINEPLUGIN)
-
-clean:
- @-rm -f $(XINEPLUGIN) *.o
-
-.PHONY: $(XINEPLUGIN)
View
59 test_interlaced/README
@@ -1,59 +0,0 @@
-Prequirements :
-
-xine-lib-1.2
-
-Get crystalhd driver and libs, compile and install it :
-
- cd /usr/src
- svn co https://archvdr.svn.sourceforge.net/svnroot/archvdr/branches/libcrystalhd
- git clone git://git.wilsonet.com/crystalhd.git/
- cd crystalhd
- git checkout aed81580a42f89e1f9d9aa6047b14d74fbb994d0
- cd driver/linux
- autoconf
- ./configure
- make
- make install
- cd /usr/src/crystalhd/linux_lib/libcrystalhd
- patch -p1 -i /usr/src/libcrystalhd/patches/flush_metadata_only.patch
- make
- make install
- cd /usr/src/
- depmod -a
- modprobe crystalhd
-
-Let's check - everything is ok ? the driver is loaded ?
-
- ls -l /dev/crystalhd
- crw-rw-rw- 1 root root 251, 0 2010-01-14 21:47 /dev/crystalhd
-
-Have a look in syslog :
-
- Loading crystalhd 0.9.27
- PCI_INFO: Vendor:0x14e4 Device:0x1612 s_vendor:0x14e4 s_device: 0x2612
- Broadcom 70012 Decoder 0000:02:00.0: PCI INT A -> GSI 17 (level, low) -> IRQ 17
- allocated 18 elem
- alloc irq_desc for 29 on node -1
- alloc kstat_irqs on node -1
- Broadcom 70012 Decoder 0000:02:00.0: irq 29 for MSI/MSI-X
- Starting BCM70012 Device
- clock is moving to 175 with n 35 with vco_mg 2
- CStopping BCM70012 Device
- Broadcom 70012 Decoder 0000:02:00.0: setting latency timer to 64
-
-Let's compile Plugin libcristalhd
-
- cd /usr/src/libcrystalhd/
- make
- make install
-
-Let's check again
-
- ls -l /usr/lib/xine/plugins/2.0/*crystalhd*
- -rwxr-xr-x 1 root root 212700 2010-01-14 22:14 /usr/lib/xine/plugins/2.0/xineplug_decode_crystalhd.so
-
-Seems ok. After of xine-ui compiling let's start it and correct .xine/config
-
- engine.decoder_priorities.crystalhd_h264:1
-
-
View
1 test_interlaced/TODO
@@ -1 +0,0 @@
-Complete rework of vc1 plugin
View
37 test_interlaced/bits_reader.h
@@ -1,37 +0,0 @@
-#include <sys/types.h>
-
-
-
-typedef struct {
- uint8_t *buffer;
- int offbits;
-} bits_reader_t;
-
-static void bits_reader_set( bits_reader_t *br, uint8_t *buf )
-{
- br->buffer = buf;
- br->offbits = 0;
-}
-
-static uint32_t read_bits( bits_reader_t *br, int nbits )
-{
- int i, nbytes;
- uint32_t ret = 0;
- uint8_t *buf;
-
- buf = br->buffer;
- nbytes = (br->offbits + nbits)/8;
- if ( ((br->offbits + nbits) %8 ) > 0 )
- nbytes++;
- for ( i=0; i<nbytes; i++ )
- ret += buf[i]<<((nbytes-i-1)*8);
- i = (4-nbytes)*8+br->offbits;
- ret = ((ret<<i)>>i)>>((nbytes*8)-nbits-br->offbits);
-
- br->offbits += nbits;
- br->buffer += br->offbits / 8;
- br->offbits %= 8;
-
- return ret;
-}
-
View
49 test_interlaced/cpb.c
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2009 Julian Scheel
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * cpb.c: Coded Picture Buffer
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "cpb.h"
-
-#include <stdlib.h>
-
-struct coded_picture* create_coded_picture()
-{
- struct coded_picture* pic = calloc(1, sizeof(struct coded_picture));
- return pic;
-}
-
-void free_coded_picture(struct coded_picture *pic)
-{
- if(!pic)
- return;
-
- release_nal_unit(pic->sei_nal);
- release_nal_unit(pic->sps_nal);
- release_nal_unit(pic->pps_nal);
- release_nal_unit(pic->slc_nal);
-
- free(pic);
-}
-
View
67 test_interlaced/cpb.h
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2009 Julian Scheel
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * cpb.h: Coded Picture Buffer
- */
-
-#ifndef CPB_H_
-#define CPB_H_
-
-#include "nal.h"
-
-enum picture_flags {
- IDR_PIC = 0x01,
- REFERENCE = 0x02,
- NOT_EXISTING = 0x04,
- INTERLACED = 0x08
-};
-
-struct coded_picture
-{
- uint32_t flag_mask;
-
- uint32_t max_pic_num;
- int32_t pic_num;
-
- uint8_t used_for_long_term_ref;
- uint32_t long_term_pic_num;
- uint32_t long_term_frame_idx;
-
- int32_t top_field_order_cnt;
- int32_t bottom_field_order_cnt;
-
- uint8_t repeat_pic;
-
- /* buffer data for the image slices, which
- * are passed to the decoder
- */
- uint32_t slice_cnt;
-
- int64_t pts;
-
- struct nal_unit *sei_nal;
- struct nal_unit *sps_nal;
- struct nal_unit *pps_nal;
- struct nal_unit *slc_nal;
-};
-
-struct coded_picture* create_coded_picture(void);
-void free_coded_picture(struct coded_picture *pic);
-
-#endif /* CPB_H_ */
View
73 test_interlaced/crystalhd.c
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2009 Edgar Hucek
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * crystalhd.c: H264 Video Decoder utilizing Broadcom Crystal HD engine
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "crystalhd.h"
-#include "crystalhd_hw.h"
-
-HANDLE hDevice = 0;
-
-void Sleep(int ms) {
- struct timespec req;
- req.tv_sec=0;
- req.tv_nsec= 1000000 * ms;
- nanosleep(&req, 0);
-}
-
-void crystalhd_decode_package (uint8_t *buf, uint32_t size) {
- int i;
-
- if(size == 0) return;
-
- printf("Decode data: \n");
-
- for(i = 0; i < ((size < 80) ? size : 80); i++) {
- printf("%02x ", ((uint8_t*)buf)[i]);
- if((i+1) % 40 == 0)
- printf("\n");
- }
- printf("\n...\n");
-}
-
-pthread_once_t once_control = PTHREAD_ONCE_INIT;
-pthread_mutex_t crystalhd_h264_lock;
-
-void init_once_routine(void) {
- hDevice = crystalhd_open();
- pthread_mutex_init(&crystalhd_h264_lock, NULL);
-}
-
-
-/*
- * The plugin catalog entry. This is the only information that this plugin
- * will export to the public.
- */
-const plugin_info_t xine_plugin_info[] EXPORTED = {
- /* { type, API, "name", version, special_info, init_function } */
- { PLUGIN_VIDEO_DECODER | PLUGIN_MUST_PRELOAD, 19, "crystalhd_h264", XINE_VERSION_CODE, &dec_info_crystalhd_h264, init_h264_plugin },
- { PLUGIN_VIDEO_DECODER | PLUGIN_MUST_PRELOAD, 19, "crystalhd_vc1", XINE_VERSION_CODE, &dec_info_crystalhd_vc1, init_vc1_plugin },
- { PLUGIN_NONE, 0, "", 0, NULL, NULL }
-};
-
View
96 test_interlaced/crystalhd.h
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2009 Edgar Hucek
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * crystalhd.h: H264 Video Decoder utilizing Broadcom Crystal HD engine
- */
-
-#ifndef CRYSTALHD_H
-#define CRYSTALHD_H
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <pthread.h>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define XINE_ENGINE_INTERNAL
-
-#include <xine/xine_internal.h>
-#include <xine/video_out.h>
-#include <xine/buffer.h>
-#include <xine/xineutils.h>
-
-#ifndef __LINUX_USER__
-#define __LINUX_USER__
-#endif
-
-#include <bc_dts_types.h>
-#include <bc_dts_defs.h>
-#include <libcrystalhd_if.h>
-
-#include <semaphore.h>
-
-extern HANDLE hDevice;
-
-void *init_h264_plugin (xine_t *xine, void *data);
-void *init_vc1_plugin (xine_t *xine, void *data);
-
-extern decoder_info_t dec_info_crystalhd_h264;
-extern decoder_info_t dec_info_crystalhd_vc1;
-
-void Sleep(int ms);
-void crystalhd_decode_package (uint8_t *buf, uint32_t size);
-
-extern pthread_once_t once_control;
-void init_once_routine(void);
-
-extern pthread_mutex_t crystalhd_lock;
-
-typedef struct decoder_buffer_s {
- uint8_t *bytestream;
- uint32_t bytestream_bytes;
- int64_t pts;
-} decoder_buffer_t;
-
-typedef struct image_buffer_s {
- uint8_t *image;
- uint32_t image_bytes;
- int width;
- int height;
- int64_t pts;
- uint64_t video_step;
- uint32_t flags;
- int interlaced;
- uint32_t picture_number;
- uint32_t stride;
-} image_buffer_t;
-
-typedef uint32_t BCM_STREAM_TYPE;
-typedef uint32_t BCM_VIDEO_ALGO;
-
-#endif
View
893 test_interlaced/crystalhd_h264.c
@@ -1,893 +0,0 @@
-/*
- * Copyright (C) 2009 Edgar Hucek
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * crystalhd_h264.c: H264 Video Decoder utilizing Broadcom Crystal HD engine
- */
-
-#define LOG
-
-#include "crystalhd.h"
-#include "crystalhd_hw.h"
-
-#include "cpb.h"
-#include "h264_parser.h"
-
-#define MAX_FRAME_SIZE 1024*1024
-
-struct buf_reader
-{
- uint8_t *buf;
- uint8_t *cur_pos;
- int len;
- int cur_offset;
-};
-
-
-typedef struct {
- video_decoder_class_t decoder_class;
-} crystalhd_h264_class_t;
-
-typedef struct crystalhd_h264_decoder_s {
- video_decoder_t video_decoder; /* parent video decoder structure */
-
- crystalhd_h264_class_t *class;
- xine_stream_t *stream;
-
- /* these are traditional variables in a video decoder object */
-
- double ratio;
-
- xine_t *xine;
-
- uint8_t *transferbuff;
-
- uint64_t video_step;
- int got_frame;
- int start_decoding;
-
- int width;
- int height;
- int y_size;
- int uv_size;
-
- int have_frame_boundary_marks;
- int wait_for_frame_start;
- int decoder_timeout;
-
- xine_list_t *image_buffer;
-
- xine_bmiheader *bih;
- unsigned char *extradata;
- int extradata_size;
-
- BC_DTS_PROC_OUT procOut;
-
- struct h264_parser *nal_parser; /* h264 nal parser. extracts stream data for vdpau */
- struct coded_picture *completed_pic;
-
- int interlaced;
-
- int last_image;
-
- pthread_t rec_thread;
- int rec_thread_stop;
-
- metronom_clock_t *clock;
-
- pthread_mutex_t rec_mutex;
-
- int reset;
-
- int64_t last_pts;
-
-} crystalhd_h264_decoder_t;
-
-static void crystalhd_h264_flush (video_decoder_t *this_gen);
-static void crystalhd_h264_reset (video_decoder_t *this_gen);
-
-/**************************************************************************
- * crystalhd_h264 specific decode functions
- *************************************************************************/
-
-/**************************************************************************
- * xine video plugin functions
- *************************************************************************/
-
-static void set_video_step(crystalhd_h264_decoder_t *this, uint32_t frame_rate) {
- switch(frame_rate) {
- case vdecRESOLUTION_720p:
- case vdecRESOLUTION_576p:
- case vdecRESOLUTION_480p:
- this->video_step = 90000/60;
- break;
- case vdecRESOLUTION_SD_DVD:
- this->video_step = 90000/50;
- break;
- case vdecRESOLUTION_PAL1:
- this->video_step = 90000/50;
- break;
- case vdecRESOLUTION_NTSC:
- this->video_step = 90000/60;
- break;
- case vdecRESOLUTION_720p50:
- this->video_step = 90000/50;
- break;
- case vdecRESOLUTION_1080i25:
- this->video_step = 90000/25;
- break;
- case vdecRESOLUTION_1080p30:
- case vdecRESOLUTION_240p30:
- this->video_step = 90000/30;
- break;
- case vdecRESOLUTION_1080p25:
- case vdecRESOLUTION_576p25:
- case vdecRESOLUTION_288p25:
- this->video_step = 90000/25;
- break;
- case vdecRESOLUTION_1080p24:
- case vdecRESOLUTION_720p24:
- this->video_step = 90000/24;
- break;
- case vdecRESOLUTION_1080i29_97:
- case vdecRESOLUTION_1080p29_97:
- case vdecRESOLUTION_720p29_97:
- case vdecRESOLUTION_480p29_97:
- case vdecRESOLUTION_240p29_97:
- this->video_step = 90000/29.97;
- break;
- case vdecRESOLUTION_1080p23_976:
- case vdecRESOLUTION_720p23_976:
- case vdecRESOLUTION_480p23_976:
- case vdecRESOLUTION_1080p0:
- case vdecRESOLUTION_576p0:
- case vdecRESOLUTION_720p0:
- case vdecRESOLUTION_480p0:
- this->video_step = 90000/23.976;
- break;
- case vdecRESOLUTION_1080i:
- case vdecRESOLUTION_480i:
- case vdecRESOLUTION_1080i0:
- case vdecRESOLUTION_480i0:
- this->video_step = 90000/25;
- break;
- case vdecRESOLUTION_720p59_94:
- //this->video_step = 90000/59.94;
- this->video_step = 90000/59.94/2;
- break;
- case vdecRESOLUTION_CUSTOM:
- case vdecRESOLUTION_480p656:
- default:
- this->video_step = 90000/25;
- break;
- }
-}
-
-static void set_ratio(crystalhd_h264_decoder_t *this, uint32_t aspect_ratio) {
- lprintf("aspect_ratio %d\n", aspect_ratio);
-
- this->ratio = (double)this->width / (double)this->height;
- switch(aspect_ratio) {
- case vdecAspectRatio12_11:
- this->ratio *= 12.0/11.0;
- case vdecAspectRatio10_11:
- this->ratio *= 10.0/11.0;
- break;
- case vdecAspectRatio16_11:
- this->ratio *= 16.0/11.0;
- break;
- case vdecAspectRatio40_33:
- this->ratio *= 40.0/33.0;
- break;
- case vdecAspectRatio24_11:
- this->ratio *= 24.0/11.0;
- break;
- case vdecAspectRatio20_11:
- this->ratio *= 20.0/11.0;
- break;
- case vdecAspectRatio32_11:
- this->ratio *= 32.0/11.0;
- break;
- case vdecAspectRatio80_33:
- this->ratio *= 80.0/33.0;
- break;
- case vdecAspectRatio18_11:
- this->ratio *= 18.0/11.0;
- break;
- case vdecAspectRatio15_11:
- this->ratio *= 15.0/11.0;
- break;
- case vdecAspectRatio64_33:
- this->ratio *= 64.0/33.0;
- break;
- case vdecAspectRatio160_99:
- this->ratio *= 160.0/99.0;
- break;
- case vdecAspectRatio4_3:
- this->ratio *= 4.0/3.0;
- break;
- case vdecAspectRatio16_9:
- this->ratio *= 16.0 / 9.0;
- break;
- case vdecAspectRatio221_1:
- this->ratio *= 2.0/1.0;
- break;
- case vdecAspectRatioUnknown:
- case vdecAspectRatioOther:
- default:
- this->ratio = (double)this->width / (double)this->height;
- break;
- }
-}
-
-static void print_setup(crystalhd_h264_decoder_t *this) {
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->width %d\n", this->width);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->height %d\n", this->height);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->interlaced %d\n", this->interlaced);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->video_step %ld\n", this->video_step);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->ratio %f\n", this->ratio);
-}
-
-static void set_video_params (crystalhd_h264_decoder_t *this) {
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->width );
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->height );
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_VIDEO_RATIO, ((double)10000*this->ratio) );
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step );
- _x_meta_info_set_utf8( this->stream, XINE_META_INFO_VIDEOCODEC, "H264/AVC (crystalhd)" );
- xine_set_param(this->stream, XINE_PARAM_VO_DEINTERLACE, this->interlaced);
- xine_event_t event;
- xine_format_change_data_t data;
- event.type = XINE_EVENT_FRAME_FORMAT_CHANGE;
- event.stream = this->stream;
- event.data = &data;
- event.data_length = sizeof(data);
- data.width = this->width;
- data.height = this->height;
- data.aspect = this->ratio;
- data.pan_scan = 1;
- xine_event_send( this->stream, &event );
-
- print_setup(this);
-}
-
-static void copy_frame(crystalhd_h264_decoder_t *this, image_buffer_t *img) {
- uint8_t *pDest;
- int line_width = img->stride/2;
- int offset = 0;
- int y;
-
- pDest = malloc(1920*1088*2);
-
- //memset(pDest, 0x80, 1920*1088*2);
-
- /*
- if(img->flags == VO_BOTTOM_FIELD) {
- offset = line_width*4;
- }
- */
-
- offset = line_width*4;
-
- for(y = img->height/2; y >= 0; y--) {
- xine_fast_memcpy(
- pDest + (y * line_width * 2) * 4,
- img->image + (y * line_width) * 4,
- line_width * 4
- );
- xine_fast_memcpy(
- pDest + (y * line_width * 2) * 4 + offset,
- img->image + (y * line_width) * 4,
- line_width * 4
- );
- }
-
- free(img->image);
-
- img->image = pDest;
-
-}
-
-static void crystalhd_h264_render (crystalhd_h264_decoder_t *this) {
- xine_list_iterator_t ite;
-
- ite = xine_list_front(this->image_buffer);
-
- if(ite!= NULL) {
- image_buffer_t *img = xine_list_get_value(this->image_buffer, ite);
- xine_list_remove(this->image_buffer, ite);
-
- if(img->image_bytes > 0) {
-
- vo_frame_t *vo_img;
-
- vo_img = this->stream->video_out->get_frame (this->stream->video_out,
- img->width, img->height, this->ratio,
- XINE_IMGFMT_YUY2, /*img->flags | this->reseti */ VO_BOTH_FIELDS);
-
- this->reset = 0;
-
- yuy2_to_yuy2(
- img->image, img->width * 2,
- vo_img->base[0], vo_img->pitches[0],
- img->width, img->height);
- vo_img->pts = img->pts;
- vo_img->duration = this->video_step;
- vo_img->bad_frame = 0;
-
- if(this->interlaced) {
- vo_img->progressive_frame = 0;
- vo_img->top_field_first = 1; /*(img->flags == VO_TOP_FIELD) ? 1 : 0;*/
- } else {
- vo_img->progressive_frame = 1;
- vo_img->top_field_first = 0;
- }
-
- vo_img->draw(vo_img, this->stream);
-
- vo_img->free(vo_img);
- }
-
- free(img->image);
- free(img);
- }
-}
-
-static void* crystalhd_h264_rec_thread (void *this_gen) {
- crystalhd_h264_decoder_t *this = (crystalhd_h264_decoder_t *) this_gen;
- BC_STATUS ret;
- BC_DTS_STATUS pStatus;
-
- while(!this->rec_thread_stop) {
-
- /* read driver status. we need the frame ready count from it */
- if(!this->got_frame) {
- ret = DtsGetDriverStatus(hDevice, &pStatus);
- if( ret == BC_STS_SUCCESS && pStatus.ReadyListCount > 0) {
- this->got_frame = 1;
- }
- }
-
- if( this->got_frame && this->start_decoding) {
-
- memset(&this->procOut, 0, sizeof(BC_DTS_PROC_OUT));
-
- /* setup frame transfer structure */
- this->procOut.PicInfo.width = this->width;
- this->procOut.PicInfo.height = this->height;
- this->procOut.YbuffSz = this->y_size/4;
- this->procOut.UVbuffSz = this->uv_size/4;
- this->procOut.PoutFlags = BC_POUT_FLAGS_SIZE;
-
- this->procOut.PicInfo.picture_number = 0;
-
- if(this->transferbuff == NULL) {
- this->transferbuff = malloc(1920*1088*2);
- }
- this->procOut.Ybuff = this->transferbuff;
- this->procOut.PoutFlags = this->procOut.PoutFlags & 0xff;
-
- if(this->interlaced) {
- this->procOut.PoutFlags |= BC_POUT_FLAGS_INTERLACED;
- }
-
- //pthread_mutex_lock(&this->rec_mutex);
- ret = DtsProcOutput(hDevice, this->decoder_timeout, &this->procOut);
- //pthread_mutex_unlock(&this->rec_mutex);
-
- /* print statistics */
- switch (ret) {
- case BC_STS_NO_DATA:
- break;
- case BC_STS_FMT_CHANGE:
- if ((this->procOut.PoutFlags & BC_POUT_FLAGS_PIB_VALID) &&
- (this->procOut.PoutFlags & BC_POUT_FLAGS_FMT_CHANGE) ) {
-
- this->interlaced = (this->procOut.PicInfo.flags & VDEC_FLAG_INTERLACED_SRC ? 1 : 0);
-
- this->width = this->procOut.PicInfo.width;
- this->height = this->procOut.PicInfo.height;
- if(this->height == 1088) this->height = 1080;
-
- this->y_size = this->width * this->height;
-
- this->uv_size = 0;
-
- this->decoder_timeout = 2500;
-
- set_ratio(this, this->procOut.PicInfo.aspect_ratio);
- set_video_step(this, this->procOut.PicInfo.frame_rate);
- set_video_params(this);
- }
- break;
- case BC_STS_SUCCESS:
- if (this->procOut.PoutFlags & BC_POUT_FLAGS_PIB_VALID) {
-
- if(this->last_image == 0) {
- this->last_image = this->procOut.PicInfo.picture_number;
- }
-
- if((this->procOut.PicInfo.picture_number - this->last_image) > 0 ) {
-
- xprintf(this->xine, XINE_VERBOSITY_LOG,"ReadyListCount %d FreeListCount %d PIBMissCount %d picture_number %d gap %d tiemStamp %ld\n",
- pStatus.ReadyListCount, pStatus.FreeListCount, pStatus.PIBMissCount,
- this->procOut.PicInfo.picture_number,
- this->procOut.PicInfo.picture_number - this->last_image,
- this->procOut.PicInfo.timeStamp);
-
- if((this->procOut.PicInfo.picture_number - this->last_image) > 1) {
- xprintf(this->xine, XINE_VERBOSITY_NONE,"ReadyListCount %d FreeListCount %d PIBMissCount %d picture_number %d gap %d tiemStamp %ld\n",
- pStatus.ReadyListCount, pStatus.FreeListCount, pStatus.PIBMissCount,
- this->procOut.PicInfo.picture_number,
- this->procOut.PicInfo.picture_number - this->last_image,
- this->procOut.PicInfo.timeStamp);
- //xprintf(this->xine, XINE_VERBOSITY_NONE,"Lost frame\n");
- }
-
- xprintf(this->xine, XINE_VERBOSITY_LOG,"VDEC_FLAG_BOTTOMFIELD %d VDEC_FLAG_TOPFIELD %d VDEC_FLAG_FIELDPAIR %d VDEC_FLAG_PROGRESSIVE_SRC %d VDEC_FLAG_INTERLACED_SRC% d\n",
- this->procOut.PicInfo.flags & VDEC_FLAG_BOTTOMFIELD,
- this->procOut.PicInfo.flags & VDEC_FLAG_TOPFIELD,
- this->procOut.PicInfo.flags & VDEC_FLAG_FIELDPAIR,
- this->procOut.PicInfo.flags & VDEC_FLAG_PROGRESSIVE_SRC,
- this->procOut.PicInfo.flags & VDEC_FLAG_INTERLACED_SRC);
-
- if(this->procOut.PicInfo.picture_number != this->last_image) {
- this->last_image = this->procOut.PicInfo.picture_number;
- }
-
- /* allocate new image buffer and push it to the image list */
- image_buffer_t *img = valloc(sizeof(image_buffer_t));
-
- img->image = this->transferbuff;
- img->image_bytes = this->procOut.YbuffSz;
- img->width = this->width;
- img->height = this->height;
- img->pts = this->procOut.PicInfo.timeStamp;
- img->video_step = this->video_step;
- img->interlaced = this->interlaced;
- img->picture_number = this->procOut.PicInfo.picture_number;
-
- if(img->width <= 720 ) {
- img->stride = 720;
- } else if (img->width <= 1280 ) {
- img->stride = 1280;
- } else {
- img->stride = 1920;
- }
-
- if(this->interlaced) {
- if(this->procOut.PicInfo.picture_number & 1) {
- img->flags = VO_BOTTOM_FIELD;
- } else {
- img->flags = VO_TOP_FIELD;
- }
-
- copy_frame(this, img);
- } else {
- img->flags = VO_BOTH_FIELDS;
- }
-
- this->transferbuff = NULL;
-
- xine_list_push_back(this->image_buffer, img);
-
- }
- }
- break;
- default:
- if (ret > 26) {
- lprintf("DtsProcOutput returned %d.\n", ret);
- } else {
- lprintf("DtsProcOutput returned %s.\n", g_DtsStatusText[ret]);
- }
- break;
- }
- }
-
- Sleep(5);
-
- }
-
- pthread_exit(NULL);
-}
-
-/*
- * This function receives a buffer of data from the demuxer layer and
- * figures out how to handle it based on its header flags.
- */
-static void crystalhd_h264_decode_data (video_decoder_t *this_gen, buf_element_t *buf) {
-
- crystalhd_h264_decoder_t *this = (crystalhd_h264_decoder_t *) this_gen;
-
- /*
- if(buf->pts) {
- this->last_pts = buf->pts;
- }
-
- if(this->last_pts) {
- char *buff = valloc(buf->size);
-
- this->start_decoding = 1;
-
- memcpy(buff, buf->content, buf->size);
- DtsProcInput(hDevice, buff, buf->size, buf->pts, 0);
- free(buff);
- }
- */
-
- //crystalhd_h264_render(this);
-
- if (buf->decoder_flags & BUF_FLAG_PREVIEW) {
- return;
- }
-
- if(buf->decoder_flags & BUF_FLAG_FRAME_START || buf->decoder_flags & BUF_FLAG_FRAME_END) {
- this->have_frame_boundary_marks = 1;
- }
-
- if (buf->decoder_flags & BUF_FLAG_FRAMERATE) {
- this->video_step = buf->decoder_info[0];
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step);
- }
-
- if(buf->decoder_flags & BUF_FLAG_STDHEADER) {
- this->have_frame_boundary_marks = 0;
-
- int size = ((xine_bmiheader *) buf->content)->biSize;
- if(!this->bih) this->bih = valloc(size);
- xine_fast_memcpy(this->bih, buf->content, sizeof(xine_bmiheader));
- this->width = this->bih->biWidth;
- this->height = this->bih->biHeight;
-
- uint8_t *extradata = buf->content + sizeof(xine_bmiheader);
- uint32_t extradata_size = this->bih->biSize - sizeof(xine_bmiheader);
- this->extradata_size = extradata_size;
- this->extradata = valloc(extradata_size);
- xine_fast_memcpy(this->extradata, extradata, extradata_size);
-
- if(extradata_size > 0) {
- parse_codec_private(this->nal_parser, extradata, extradata_size);
- }
- } else if (buf->decoder_flags & BUF_FLAG_SPECIAL) {
- this->have_frame_boundary_marks = 0;
-
- if (buf->decoder_info[1] == BUF_SPECIAL_DECODER_CONFIG &&
- !this->extradata_size) {
- uint8_t *extradata = buf->decoder_info_ptr[2];
- uint32_t extradata_size = buf->decoder_info[2];
- this->extradata_size = extradata_size;
- this->extradata = valloc(extradata_size);
- xine_fast_memcpy(this->extradata, extradata, extradata_size);
-
- if(extradata_size > 0) {
- parse_codec_private(this->nal_parser, extradata, extradata_size);
- }
- }
- } else {
- int len = 0;
- decoder_buffer_t decode_buffer;
- decode_buffer.bytestream_bytes = 0;
-
- while(len < buf->size && !(this->wait_for_frame_start && !(buf->decoder_flags & BUF_FLAG_FRAME_START))) {
-
- this->wait_for_frame_start = 0;
-
- len += parse_frame(this->nal_parser, buf->content + len, buf->size - len,
- buf->pts,
- &decode_buffer.bytestream, &decode_buffer.bytestream_bytes, &this->completed_pic);
-
- if(this->completed_pic &&
- this->completed_pic->sps_nal != NULL &&
- this->completed_pic->sps_nal->sps.pic_width > 0 &&
- this->completed_pic->sps_nal->sps.pic_height > 0) {
-
- this->start_decoding = 1;
-
- decode_buffer.pts = this->completed_pic->pts;
-
- BC_STATUS ret;
-
- ret = DtsProcInput(hDevice, decode_buffer.bytestream, decode_buffer.bytestream_bytes, this->completed_pic->pts, 0);
-
- if (ret == BC_STS_BUSY) {
- xprintf(this->xine, XINE_VERBOSITY_LOG,"decoder BC_STS_BUSY\n");
- DtsFlushInput(hDevice, 4);
- DtsProcInput(hDevice, decode_buffer.bytestream, decode_buffer.bytestream_bytes, this->completed_pic->pts, 0);
- }
-
- crystalhd_h264_render(this);
- }
-
- if(decode_buffer.bytestream_bytes > 0) {
- free(decode_buffer.bytestream);
- decode_buffer.bytestream_bytes = 0;
- }
-
- if(this->completed_pic) {
- free_coded_picture(this->completed_pic);
- }
-
- if(this->nal_parser->last_nal_res == 3)
- crystalhd_h264_flush(this_gen);
- }
- }
-
- if(buf->decoder_flags & BUF_FLAG_FRAME_END) {
- //printf("next pts: %lld\n", buf->pts);
- this->wait_for_frame_start = 0;
- }
-}
-
-static void crystalhd_h264_clear_all_pts(crystalhd_h264_decoder_t *this) {
-
- xine_list_iterator_t ite;
- while ((ite = xine_list_front(this->image_buffer)) != NULL) {
- image_buffer_t *img = xine_list_get_value(this->image_buffer, ite);
- img->pts = 0;
- }
-
- if(hDevice) {
- DtsFlushInput(hDevice, 2);
- }
-
-}
-
-static void crystalhd_h264_clear_worker_buffers(crystalhd_h264_decoder_t *this) {
- xine_list_iterator_t ite;
-
- lprintf("crystalhd_h264_clear_worker_buffers enter\n");
-
- this->got_frame = 0;
-
- if(hDevice) {
- DtsFlushInput(hDevice, 2);
- }
-
- while ((ite = xine_list_front(this->image_buffer)) != NULL) {
- image_buffer_t *img = xine_list_get_value(this->image_buffer, ite);
- free(img->image);
- free(img);
- xine_list_remove(this->image_buffer, ite);
- }
-
- lprintf("crystalhd_h264_clear_worker_buffers leave\n");
-}
-
-static void crystalhd_h264_destroy_workers(crystalhd_h264_decoder_t *this) {
-
- if(this->rec_thread) {
- this->rec_thread_stop = 1;
- pthread_join(this->rec_thread, NULL);
- }
-
- pthread_mutex_destroy(&this->rec_mutex);
-
-}
-
-static void crystalhd_h264_setup_workers(crystalhd_h264_decoder_t *this) {
-
- pthread_attr_t thread_attr;
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
- pthread_create(&this->rec_thread, &thread_attr,crystalhd_h264_rec_thread,(void *)this);
- pthread_attr_destroy(&thread_attr);
-
- pthread_mutexattr_t mutex_attr;
- pthread_mutexattr_init(&mutex_attr);
- pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_PRIVATE);
- pthread_mutex_init(&this->rec_mutex, &mutex_attr);
- pthread_mutexattr_destroy(&mutex_attr);
-
-}
-
-/*
- * This function is called when xine needs to flush the system.
- */
-static void crystalhd_h264_flush (video_decoder_t *this_gen) {
- crystalhd_h264_decoder_t *this = (crystalhd_h264_decoder_t*) this_gen;
-
- crystalhd_h264_clear_worker_buffers(this);
-
- this->reset = VO_NEW_SEQUENCE_FLAG;
-
- xprintf(this->xine, XINE_VERBOSITY_LOG, "crystalhd_h264: crystalhd_h264_decode_flush\n");
-}
-
-/*
- * This function resets the video decoder.
- */
-static void crystalhd_h264_reset (video_decoder_t *this_gen) {
- crystalhd_h264_decoder_t *this = (crystalhd_h264_decoder_t *) this_gen;
-
- crystalhd_h264_clear_worker_buffers(this);
-
- // Doing a full parser reinit here works more reliable than
- // resetting
-
- //reset_parser(this->nal_parser);
- free_parser(this->nal_parser);
- this->nal_parser = init_parser(this->xine);
-
- this->last_image = 0;
-
- crystalhd_h264_clear_worker_buffers(this);
-
- if(this->extradata_size > 0) {
- parse_codec_private(this->nal_parser, this->extradata, this->extradata_size);
- this->wait_for_frame_start = this->have_frame_boundary_marks;
- }
-
- this->reset = VO_NEW_SEQUENCE_FLAG;
-
- xprintf(this->xine, XINE_VERBOSITY_LOG, "crystalhd_h264: crystalhd_h264_reset\n");
-}
-
-/*
- * The decoder should forget any stored pts values here.
- */
-static void crystalhd_h264_discontinuity (video_decoder_t *this_gen) {
- crystalhd_h264_decoder_t *this = (crystalhd_h264_decoder_t *) this_gen;
-
- crystalhd_h264_clear_all_pts(this);
-
- this->reset = VO_NEW_SEQUENCE_FLAG;
-
- xprintf(this->xine, XINE_VERBOSITY_LOG, "crystalhd_h264: crystalhd_h264_discontinuity\n");
-}
-
-/*
- * This function frees the video decoder instance allocated to the decoder.
- */
-static void crystalhd_h264_dispose (video_decoder_t *this_gen) {
-
- crystalhd_h264_decoder_t *this = (crystalhd_h264_decoder_t *) this_gen;
-
- crystalhd_h264_destroy_workers(this);
-
- hDevice = crystalhd_stop(this->xine, hDevice);
-
- if( this->extradata ) {
- free( this->extradata );
- this->extradata = NULL;
- }
-
- if(this->bih) {
- free(this->bih);
- this->bih = NULL;
- }
-
- free(this->transferbuff);
- this->transferbuff = NULL;
-
- crystalhd_h264_clear_worker_buffers(this);
-
- free_parser (this->nal_parser);
- free (this_gen);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "crystalhd_h264: crystalhd_h264_dispose\n");
-}
-
-/*
- * exported plugin catalog entry
- */
-/*
- * This function allocates, initializes, and returns a private video
- * decoder structure.
- */
-static video_decoder_t *open_plugin (video_decoder_class_t *class_gen, xine_stream_t *stream) {
-
- crystalhd_h264_decoder_t *this ;
-
- this = (crystalhd_h264_decoder_t *) calloc(1, sizeof(crystalhd_h264_decoder_t));
-
- this->video_decoder.decode_data = crystalhd_h264_decode_data;
- this->video_decoder.flush = crystalhd_h264_flush;
- this->video_decoder.reset = crystalhd_h264_reset;
- this->video_decoder.discontinuity = crystalhd_h264_discontinuity;
- this->video_decoder.dispose = crystalhd_h264_dispose;
-
-
- this->stream = stream;
- this->xine = stream->xine;
- this->class = (crystalhd_h264_class_t *) class_gen;
- this->clock = this->xine->clock;
-
- this->wait_for_frame_start = 0;
- this->transferbuff = NULL;
-
- this->video_step = 0;
- this->ratio = 0;
- this->got_frame = 0;
-
- this->width = 1920;
- this->height = 1082;
- this->y_size = this->width * this->height * 2;
- this->uv_size = 0;
-
- this->bih = NULL;
- this->extradata = NULL;
-
- this->start_decoding = 0;
- this->decoder_timeout = 2500;
-
- memset(&this->procOut, 0, sizeof(BC_DTS_PROC_OUT));
-
- this->interlaced = 0;
- this->last_image = 0;
-
- this->rec_thread_stop = 0;
-
- this->image_buffer = xine_list_new();
-
- this->nal_parser = init_parser(this->xine);
-
- if(hDevice) {
- hDevice = crystalhd_start(this->xine, hDevice, BC_STREAM_TYPE_ES, BC_VID_ALGO_H264);
- }
-
- this->reset = VO_NEW_SEQUENCE_FLAG;
-
- this->last_pts = 0;
-
- crystalhd_h264_setup_workers(this);
-
- return &this->video_decoder;
-}
-
-/*
- * This function allocates a private video decoder class and initializes
- * the class's member functions.
- */
-void *init_h264_plugin (xine_t *xine, void *data) {
-
- crystalhd_h264_class_t *this;
-
- this = (crystalhd_h264_class_t *) calloc(1, sizeof(crystalhd_h264_class_t));
-
- this->decoder_class.open_plugin = open_plugin;
- this->decoder_class.identifier = "crystalhd_h264";
- this->decoder_class.description =
- N_("crystalhd_h264: h264 decoder plugin using CrystalHD hardware decoding.");
- this->decoder_class.dispose = default_video_decoder_class_dispose;
-
- pthread_once( &once_control, init_once_routine );
-
- return this;
-}
-
-/*
- * This is a list of all of the internal xine video buffer types that
- * this decoder is able to handle. Check src/xine-engine/buffer.h for a
- * list of valid buffer types (and add a new one if the one you need does
- * not exist). Terminate the list with a 0.
- */
-uint32_t video_types_h264[] = {
- /* BUF_VIDEO_FOOVIDEO, */
- BUF_VIDEO_H264,
- /*BUF_VIDEO_MPEG,*/
- 0
-};
-
-/*
- * This data structure combines the list of supported xine buffer types and
- * the priority that the plugin should be given with respect to other
- * plugins that handle the same buffer type. A plugin with priority (n+1)
- * will be used instead of a plugin with priority (n).
- */
-decoder_info_t dec_info_crystalhd_h264 = {
- video_types_h264, /* supported types */
- 7 /* priority */
-};
View
166 test_interlaced/crystalhd_hw.c
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2009 Edgar Hucek
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * crystalhd_hw.c: H264 Video Decoder utilizing Broadcom Crystal HD engine
- */
-
-#include "crystalhd.h"
-
-const char* g_DtsStatusText[] = {
- "BC_STS_SUCCESS",
- "BC_STS_INV_ARG",
- "BC_STS_BUSY",
- "BC_STS_NOT_IMPL",
- "BC_STS_PGM_QUIT",
- "BC_STS_NO_ACCESS",
- "BC_STS_INSUFF_RES",
- "BC_STS_IO_ERROR",
- "BC_STS_NO_DATA",
- "BC_STS_VER_MISMATCH",
- "BC_STS_TIMEOUT",
- "BC_STS_FW_CMD_ERR",
- "BC_STS_DEC_NOT_OPEN",
- "BC_STS_ERR_USAGE",
- "BC_STS_IO_USER_ABORT",
- "BC_STS_IO_XFR_ERROR",
- "BC_STS_DEC_NOT_STARTED",
- "BC_STS_FWHEX_NOT_FOUND",
- "BC_STS_FMT_CHANGE",
- "BC_STS_HIF_ACCESS",
- "BC_STS_CMD_CANCELLED",
- "BC_STS_FW_AUTH_FAILED",
- "BC_STS_BOOTLOADER_FAILED",
- "BC_STS_CERT_VERIFY_ERROR",
- "BC_STS_DEC_EXIST_OPEN",
- "BC_STS_PENDING",
- "BC_STS_CLK_NOCHG"
-};
-
-HANDLE crystalhd_open () {
-
- BC_STATUS res;
- uint32_t mode = DTS_PLAYBACK_MODE | DTS_LOAD_FILE_PLAY_FW | DTS_PLAYBACK_DROP_RPT_MODE | DTS_DFLT_RESOLUTION(vdecRESOLUTION_CUSTOM) /*| DTS_SINGLE_THREADED_MODE */;
- HANDLE hDevice = NULL;
-
- res = DtsDeviceOpen(&hDevice, mode);
- if (res != BC_STS_SUCCESS) {
- printf("crystalhd_h264: ERROR: Failed to open Broadcom Crystal HD\n");
- return 0;
- }
-
- printf("crystalhd_h264: open device done\n");
-
- return hDevice;
-
-}
-
-/*
-HANDLE crystalhd_close(xine_t *xine, HANDLE hDevice) {
-
- BC_STATUS res;
-
- if(hDevice) {
- res = DtsDeviceClose(hDevice);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: ERROR: DtsDeviceClose\n");
- }
- }
-
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: clsoe open done\n");
-
- return 0;
-}
-*/
-
-HANDLE crystalhd_stop (xine_t *xine, HANDLE hDevice) {
-
- BC_STATUS res;
-
- if(hDevice) {
-
- res = DtsFlushRxCapture(hDevice, TRUE);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: ERROR: DtsFlushRxCapture\n");
- }
-
- res = DtsStopDecoder(hDevice);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: ERROR: DtsStopDecoder\n");
- }
-
- res = DtsCloseDecoder(hDevice);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: ERROR: DtsCloseDecoder\n");
- }
-
- }
-
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: stop device done\n");
-
- return hDevice;
-}
-
-HANDLE crystalhd_start (xine_t *xine, HANDLE hDevice, BCM_STREAM_TYPE stream_type, BCM_VIDEO_ALGO algo) {
-
- BC_STATUS res;
-
- if(hDevice) {
-
- hDevice = crystalhd_stop (xine, hDevice);
- /* Init BCM70010 */
- res = DtsOpenDecoder(hDevice, stream_type);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: Failed to open decoder\n");
- return hDevice;
- }
-
- res = DtsSetVideoParams(hDevice, algo, FALSE, FALSE, FALSE, 0 /* | 0x80 */);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: Failed to set video params\n");
- }
-
- res = DtsSet422Mode(hDevice, MODE422_YUY2);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: Failed to set 422 mode\n");
- }
-
- /*
- res = DtsSetColorSpace(hDevice, OUTPUT_MODE422_YUY2);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: Failed to set 422 mode\n");
- }
- */
-
- res = DtsStartDecoder(hDevice);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: Failed to start decoder\n");
- }
-
- res = DtsStartCapture(hDevice);
- if (res != BC_STS_SUCCESS) {
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: Failed to start capture\n");
- }
-
- }
-
- xprintf(xine, XINE_VERBOSITY_LOG,"crystalhd: start device done\n");
-
- return hDevice;
-}
-
View
41 test_interlaced/crystalhd_hw.h
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2009 Edgar Hucek
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * crystalhd_hw.h: H264 Video Decoder utilizing Broadcom Crystal HD engine
- */
-
-#ifndef CRYSTALHD_HW_H
-#define CRYSTALHD_HW_H
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "crystalhd.h"
-
-extern const char* g_DtsStatusText[];
-
-HANDLE crystalhd_open();
-/*
-HANDLE crystalhd_close(xine_t *xine, HANDLE hDevice);
-*/
-HANDLE crystalhd_start(xine_t *xine, HANDLE hDevice, BCM_STREAM_TYPE stream_type, BCM_VIDEO_ALGO algo);
-HANDLE crystalhd_stop(xine_t *xine, HANDLE hDevice);
-
-#endif
View
1,348 test_interlaced/crystalhd_vc1.c
@@ -1,1348 +0,0 @@
-/*
- * Copyright (C) 2009 Edgar Hucek
- *
- * This file is part of xine, a free video player.
- *
- * xine 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.
- *
- * xine 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
- * crystalhd_vc1.c: H264 Video Decoder utilizing Broadcom Crystal HD engine
- */
-
-#define LOG
-
-#include "crystalhd.h"
-#include "crystalhd_hw.h"
-
-#include "bits_reader.h"
-
-#define sequence_header_code 0x0f
-#define sequence_end_code 0x0a
-#define entry_point_code 0x0e
-#define frame_start_code 0x0d
-#define field_start_code 0x0c
-#define slice_start_code 0x0b
-
-#define PICTURE_FRAME 0
-#define PICTURE_FRAME_INTERLACE 2
-#define PICTURE_FIELD_INTERLACE 3
-
-#define I_FRAME 0
-#define P_FRAME 1
-#define B_FRAME 3
-#define BI_FRAME 4
-
-#define FIELDS_I_I 0
-#define FIELDS_I_P 1
-#define FIELDS_P_I 2
-#define FIELDS_P_P 3
-#define FIELDS_B_B 4
-#define FIELDS_B_BI 5
-#define FIELDS_BI_B 6
-#define FIELDS_BI_BI 7
-
-#define MODE_STARTCODE 0
-#define MODE_FRAME 1
-
-#define PROFILE_VC1_SIMPLE 1
-#define PROFILE_VC1_ADVANCED 2
-#define PROFILE_VC1_MAIN 3
-
-const double aspect_ratio[] = {
- 0.0,
- 1.0,
- 12./11.,
- 10./11.,
- 16./11.,
- 40./33.,
- 24./11.,
- 20./11.,
- 32./11.,
- 80./33.,
- 18./11.,
- 15./11.,
- 64./33.,
- 160./99.
-};
-
-typedef struct {
- video_decoder_class_t decoder_class;
-} crystalhd_vc1_class_t;
-
-typedef struct {
- int slices;
- int fptype;
- int field;
- int header_size;
- int skipped;
- uint8_t picture_type;
- uint8_t finterpflag;
- uint8_t maxbframes;
- uint8_t interlace;
- uint8_t rangered;
- uint8_t frame_coding_mode;
-} picture_t;
-
-typedef struct {
- uint32_t coded_width;
- uint32_t coded_height;
-
- uint64_t video_step; /* frame duration in pts units */
- double ratio;
- uint32_t profile;
-
- int mode;
- int have_header;
-
- uint8_t *buf; /* accumulate data */
- int bufseek;
- int start;
- int code_start, current_code;
- uint32_t bufsize;
- uint32_t bufpos;
-
- picture_t picture;
- int64_t seq_pts;
- int64_t cur_pts;
-
- bits_reader_t br;
-} sequence_t;
-
-typedef struct crystalhd_vc1_decoder_s {
- video_decoder_t video_decoder; /* parent video decoder structure */
-
- crystalhd_vc1_class_t *class;
- xine_stream_t *stream;
-
- /* these are traditional variables in a video decoder object */
-
- double ratio;
-
- xine_t *xine;
-
- unsigned char *transferbuff;
-
- int64_t next_pts;
- uint64_t video_step;
- int got_frame;
-
- int width;
- int height;
- int y_size;
- int uv_size;
-
- int nal_size_length;
- int decoder_timeout;
-
-
- BC_DTS_PROC_OUT procOut;
- uint32_t videoAlg;
-
- sequence_t sequence;
-
- int interlaced;
-
- int last_image;
-
- int start_decoding;
-
- xine_list_t *image_buffer;
- xine_list_t *decoder_buffer;
-
- pthread_t render_thread;
- int render_thread_stop;
- pthread_mutex_t render_mutex;
- pthread_t rec_thread;
- int rec_thread_stop;
- pthread_mutex_t rec_mutex;
- pthread_t send_thread;
- int send_thread_stop;
- pthread_mutex_t send_mutex;
-
- pthread_mutex_t image_mutex;
-} crystalhd_vc1_decoder_t;
-
-static void crystalhd_vc1_flush (video_decoder_t *this_gen);
-
-/**************************************************************************
- * crystalhd_vc1 specific decode functions
- *************************************************************************/
-
-/**************************************************************************
- * xine video plugin functions
- *************************************************************************/
-
-static void reset_picture( picture_t *pic )
-{
- pic->slices = 1;
-}
-
-static void init_picture( picture_t *pic )
-{
- memset( pic, 0, sizeof( picture_t ) );
-}
-
-static void reset_sequence( sequence_t *sequence ) {
- lprintf( "reset_sequence\n" );
- sequence->bufpos = 0;
- sequence->bufseek = 0;
- sequence->start = -1;
- sequence->code_start = sequence->current_code = 0;
- sequence->seq_pts = sequence->cur_pts = 0;
- reset_picture( &sequence->picture );
-}
-
-static void init_sequence( sequence_t *sequence ) {
- lprintf( "init_sequence\n" );
- sequence->have_header = 0;
- sequence->profile = PROFILE_VC1_SIMPLE;
- sequence->ratio = 0;
- sequence->video_step = 0;
- reset_sequence( sequence );
-}
-
-static void set_video_step(crystalhd_vc1_decoder_t *this, uint32_t frame_rate) {
- switch(frame_rate) {
- case vdecRESOLUTION_720p:
- case vdecRESOLUTION_576p:
- case vdecRESOLUTION_480p:
- this->video_step = 90000/60;
- break;
- case vdecRESOLUTION_SD_DVD:
- this->video_step = 90000/50;
- break;
- case vdecRESOLUTION_PAL1:
- this->interlaced = TRUE;
- this->video_step = 90000/50;
- break;
- case vdecRESOLUTION_NTSC:
- this->interlaced = TRUE;
- this->video_step = 90000/60;
- break;
- case vdecRESOLUTION_720p50:
- this->video_step = 90000/50;
- break;
- case vdecRESOLUTION_1080i25:
- this->interlaced = TRUE;
- this->video_step = 90000/25;
- break;
- case vdecRESOLUTION_1080p30:
- case vdecRESOLUTION_240p30:
- this->video_step = 90000/30;
- break;
- case vdecRESOLUTION_1080p25:
- case vdecRESOLUTION_576p25:
- case vdecRESOLUTION_288p25:
- this->video_step = 90000/25;
- break;
- case vdecRESOLUTION_1080p24:
- case vdecRESOLUTION_720p24:
- this->video_step = 90000/24;
- break;
- case vdecRESOLUTION_1080i29_97:
- case vdecRESOLUTION_1080p29_97:
- case vdecRESOLUTION_720p29_97:
- case vdecRESOLUTION_480p29_97:
- case vdecRESOLUTION_240p29_97:
- this->video_step = 90000/23.97;
- break;
- case vdecRESOLUTION_1080p23_976:
- case vdecRESOLUTION_720p23_976:
- case vdecRESOLUTION_480p23_976:
- case vdecRESOLUTION_1080p0:
- case vdecRESOLUTION_576p0:
- case vdecRESOLUTION_720p0:
- case vdecRESOLUTION_480p0:
- this->video_step = 90000/23.976;
- break;
- case vdecRESOLUTION_1080i:
- case vdecRESOLUTION_480i:
- case vdecRESOLUTION_1080i0:
- case vdecRESOLUTION_480i0:
- case vdecRESOLUTION_720p59_94:
- this->interlaced = TRUE;
- this->video_step = 90000/59.94;
- break;
- case vdecRESOLUTION_CUSTOM:
- case vdecRESOLUTION_480p656:
- default:
- this->video_step = 90000/25;
- break;
- }
-}
-
-static void set_ratio(crystalhd_vc1_decoder_t *this, uint32_t aspect_ratio) {
- lprintf("aspect_ratio %d\n", aspect_ratio);
-
- this->ratio = (double)this->width / (double)this->height;
- switch(aspect_ratio) {
- case vdecAspectRatio12_11:
- this->ratio *= 12.0/11.0;
- case vdecAspectRatio10_11:
- this->ratio *= 10.0/11.0;
- break;
- case vdecAspectRatio16_11:
- this->ratio *= 16.0/11.0;
- break;
- case vdecAspectRatio40_33:
- this->ratio *= 40.0/33.0;
- break;
- case vdecAspectRatio24_11:
- this->ratio *= 24.0/11.0;
- break;
- case vdecAspectRatio20_11:
- this->ratio *= 20.0/11.0;
- break;
- case vdecAspectRatio32_11:
- this->ratio *= 32.0/11.0;
- break;
- case vdecAspectRatio80_33:
- this->ratio *= 80.0/33.0;
- break;
- case vdecAspectRatio18_11:
- this->ratio *= 18.0/11.0;
- break;
- case vdecAspectRatio15_11:
- this->ratio *= 15.0/11.0;
- break;
- case vdecAspectRatio64_33:
- this->ratio *= 64.0/33.0;
- break;
- case vdecAspectRatio160_99:
- this->ratio *= 160.0/99.0;
- break;
- case vdecAspectRatio4_3:
- this->ratio *= 4.0/3.0;
- break;
- case vdecAspectRatio16_9:
- this->ratio *= 16.0 / 9.0;
- break;
- case vdecAspectRatio221_1:
- this->ratio *= 2.0/1.0;
- break;
- case vdecAspectRatioUnknown:
- case vdecAspectRatioOther:
- default:
- this->ratio = (double)this->width / (double)this->height;
- break;
- }
-}
-
-static void print_setup(crystalhd_vc1_decoder_t *this) {
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->width %d\n", this->width);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->height %d\n", this->height);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->interlaced %d\n", this->interlaced);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->video_step %ld\n", this->video_step);
- xprintf(this->xine, XINE_VERBOSITY_LOG, "this->ratio %f\n", this->ratio);
-}
-
-static void set_video_params (crystalhd_vc1_decoder_t *this) {
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, this->width );
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_VIDEO_HEIGHT, this->height );
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_VIDEO_RATIO, ((double)10000*this->ratio) );
- _x_stream_info_set( this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step );
- _x_meta_info_set_utf8( this->stream, XINE_META_INFO_VIDEOCODEC, "VC1/WMV9 (crystalhd)" );
- xine_event_t event;
- xine_format_change_data_t data;
- event.type = XINE_EVENT_FRAME_FORMAT_CHANGE;
- event.stream = this->stream;
- event.data = &data;
- event.data_length = sizeof(data);
- data.width = this->width;
- data.height = this->height;
- data.aspect = this->ratio;
- data.pan_scan = 1;
- xine_event_send( this->stream, &event );
-
- print_setup(this);
-}
-
-static void set_video_vo_flags(crystalhd_vc1_decoder_t *this, uint32_t *flags) {
- *flags = VO_BOTH_FIELDS;
- *flags |= VO_PAN_SCAN_FLAG;
-}
-
-static void crystalhd_vc1_render (crystalhd_vc1_decoder_t *this, image_buffer_t *img) {
- vo_frame_t *vo_img;
-
- vo_img = this->stream->video_out->get_frame (this->stream->video_out,
- img->width, (this->interlaced) ? img->height / 2 : img->height, this->ratio,
- XINE_IMGFMT_YUY2, img->flags);
-
- yuy2_to_yuy2(
- img->image, img->width * 2,
- vo_img->base[0], vo_img->pitches[0],
- img->width, (this->interlaced) ? img->height / 2 : img->height);
-
- vo_img->pts = img->pts;
- vo_img->duration = img->video_step;
- vo_img->bad_frame = 0;
-
- vo_img->draw(vo_img, this->stream);
-
- /*
- lprintf("vo_img->pts %lld img->pts %lld vo_img->duration %d img->video_step %lld picture_number %d\n",
- vo_img->pts, img->pts, vo_img->duration, img->video_step, img->picture_number);
- */
-
- vo_img->free(vo_img);
-}
-
-static void* crystalhd_vc1_render_thread (void *this_gen) {
-
- crystalhd_vc1_decoder_t *this = (crystalhd_vc1_decoder_t *) this_gen;
-
- while(!this->render_thread_stop) {
-
- pthread_mutex_lock(&this->render_mutex);
-
- pthread_mutex_lock(&this->image_mutex);
-
- xine_list_iterator_t ite;
-
- ite = xine_list_front(this->image_buffer);
-
- //lprintf("xine_list_size(this->image_buffer) %d\n", xine_list_size(this->image_buffer));
-
- if(ite!= NULL) {
- image_buffer_t *img = xine_list_get_value(this->image_buffer, ite);
- xine_list_remove(this->image_buffer, ite);
- pthread_mutex_unlock(&this->image_mutex);
-
- if(img->image_bytes > 0) {
- crystalhd_vc1_render(this, img);
- }
-
- free(img->image);
- free(img);
- } else {
- pthread_mutex_unlock(&this->image_mutex);
- }
-
- pthread_mutex_unlock(&this->render_mutex);
-
- }
-
- pthread_exit(NULL);
-}
-
-static void* crystalhd_vc1_send_thread (void *this_gen) {
-
- BC_STATUS ret;
- crystalhd_vc1_decoder_t *this = (crystalhd_vc1_decoder_t *) this_gen;
-
- while(!this->send_thread_stop) {
-
- pthread_mutex_lock(&this->send_mutex);
-
- xine_list_iterator_t ite;
- ite = xine_list_front(this->decoder_buffer);
-
- if(ite != NULL) {
-
- decoder_buffer_t *decode_buffer = xine_list_get_value(this->decoder_buffer, ite);
-
- ret = DtsProcInput(hDevice, decode_buffer->bytestream, decode_buffer->bytestream_bytes, decode_buffer->pts, 0);
-
- if (ret == BC_STS_SUCCESS) {
- free(decode_buffer->bytestream);
- xine_list_remove(this->decoder_buffer, ite);
- } else if (ret == BC_STS_BUSY) {
- lprintf("decoder BC_STS_BUSY\n");
- DtsFlushInput(hDevice, 4);
- }
- }
-
- pthread_mutex_unlock(&this->send_mutex);
-
- }
- pthread_exit(NULL);
-}
-
-static void crystalhd_vc1_handle_buffer (crystalhd_vc1_decoder_t *this, buf_element_t *buf,
- uint8_t *bytestream, uint32_t bytestream_bytes) {
-
- //lprintf("crystalhd_vc1_handle_buffer size %d\n", bytestream_bytes);
-
- if(bytestream_bytes == 0) return;
-
- if(hDevice == 0) return;
-
- if(!this->start_decoding) return;
-
- decoder_buffer_t *decode_buffer = calloc(1, sizeof(decoder_buffer_t));
-
- decode_buffer->bytestream_bytes = bytestream_bytes;
-
- decode_buffer->bytestream = calloc(1, decode_buffer->bytestream_bytes);
-
- if(buf->pts != 0 && buf->pts != this->next_pts) {
- this->next_pts = buf->pts;
- }
- decode_buffer->pts = this->next_pts;
- this->next_pts = 0;
-
- xine_fast_memcpy(decode_buffer->bytestream, bytestream, bytestream_bytes);
-
- //crystalhd_decode_package(decode_buffer->bytestream, decode_buffer->bytestream_bytes);
-
- pthread_mutex_lock(&this->send_mutex);
- xine_list_push_back(this->decoder_buffer, decode_buffer);
- pthread_mutex_unlock(&this->send_mutex);
-}
-
-static void* crystalhd_vc1_rec_thread (void *this_gen) {
- crystalhd_vc1_decoder_t *this = (crystalhd_vc1_decoder_t *) this_gen;
- BC_STATUS ret;
- BC_DTS_STATUS pStatus;
-
- while(!this->rec_thread_stop) {
-
- pthread_mutex_lock(&this->rec_mutex);
-
- /* read driver status. we need the frame ready count from it */
- if(!this->got_frame) {
- ret = DtsGetDriverStatus(hDevice, &pStatus);
- if( ret == BC_STS_SUCCESS && pStatus.ReadyListCount > 0) {
- this->got_frame = 1;
- }
- }
-
- if( this->got_frame ) {
-
- //DtsGetDriverStatus(hDevice, &pStatus);
-
- memset(&this->procOut, 0, sizeof(BC_DTS_PROC_OUT));
-
- /* setup frame transfer structure */
- this->procOut.PicInfo.width = this->width;
- this->procOut.PicInfo.height = this->height;
- this->procOut.YbuffSz = this->y_size/4;
- this->procOut.UVbuffSz = this->uv_size/4;
- this->procOut.PoutFlags = BC_POUT_FLAGS_SIZE;
-
- this->procOut.PicInfo.picture_number = 0;
-
- if(this->transferbuff == NULL) {
- this->transferbuff = malloc(1920*1088*2);
- }
- this->procOut.Ybuff = this->transferbuff;
-
- if(this->interlaced) {
- this->procOut.PoutFlags |= BC_POUT_FLAGS_INTERLACED;
- }
-
- this->procOut.PoutFlags = this->procOut.PoutFlags & 0xff;
-
- ret = DtsProcOutput(hDevice, this->decoder_timeout, &this->procOut);
-
- /* print statistics */
- switch (ret) {
- case BC_STS_NO_DATA:
- break;
- case BC_STS_FMT_CHANGE:
- if ((this->procOut.PoutFlags & BC_POUT_FLAGS_PIB_VALID) &&
- (this->procOut.PoutFlags & BC_POUT_FLAGS_FMT_CHANGE) ) {
-
- this->interlaced = (this->procOut.PicInfo.flags & VDEC_FLAG_INTERLACED_SRC ? 1 : 0);
-
- this->width = this->procOut.PicInfo.width;
- this->height = this->procOut.PicInfo.height;
- if(this->height == 1088) this->height = 1080;
-
- if(this->interlaced) {
- this->y_size = this->width * this->height;
- } else {
- this->y_size = this->width * this->height * 2;
- }
-
- this->uv_size = 0;
-
- this->decoder_timeout = 2000;
-
- set_ratio(this, this->procOut.PicInfo.aspect_ratio);
- set_video_step(this, this->procOut.PicInfo.frame_rate);
- set_video_params(this);
- }
- break;
- case BC_STS_SUCCESS:
- if (this->procOut.PoutFlags & BC_POUT_FLAGS_PIB_VALID ||
- this->procOut.PoutFlags & BC_POUT_FLAGS_FLD_BOT) {
-
- if(this->last_image == 0) {
- this->last_image = this->procOut.PicInfo.picture_number;
- }
-
- if((this->procOut.PicInfo.picture_number - this->last_image) > 0 ) {
- //if(this->procOut.PicInfo.timeStamp && (this->procOut.PicInfo.timeStamp != this->last_out_pts)) {
-
- /*
- lprintf("ReadyListCount %d FreeListCount %d PIBMissCount %d picture_number %d gap %d\n",
- pStatus.ReadyListCount, pStatus.FreeListCount, pStatus.PIBMissCount,
- this->procOut.PicInfo.picture_number,
- this->procOut.PicInfo.picture_number - this->last_image);
- */
-
- if(this->procOut.PicInfo.picture_number != this->last_image) {
- this->last_image = this->procOut.PicInfo.picture_number;
- }
-
- /* allocate new image buffer and push it to the image list */
- image_buffer_t *img = malloc(sizeof(image_buffer_t));
-
- img->image = this->transferbuff;
- img->image_bytes = this->procOut.YbuffSz;
- img->width = this->width;
- img->height = this->height;
- img->pts = this->procOut.PicInfo.timeStamp;
- img->video_step = this->video_step;
- img->interlaced = this->interlaced;
- img->picture_number = this->procOut.PicInfo.picture_number;
-
- set_video_vo_flags(this, &img->flags);
-
- this->transferbuff = NULL;
-
- pthread_mutex_lock(&this->image_mutex);
- xine_list_push_back(this->image_buffer, img);
- pthread_mutex_unlock(&this->image_mutex);
- }
- }
- break;
- default:
- if (ret > 26) {
- lprintf("DtsProcOutput returned %d.\n", ret);
- } else {
- lprintf("DtsProcOutput returned %s.\n", g_DtsStatusText[ret]);
- }
- break;
- }
- }
-
- pthread_mutex_unlock(&this->rec_mutex);
-
- //Sleep(2);
-
- }
- pthread_exit(NULL);
-}
-
-static void sequence_header_advanced( crystalhd_vc1_decoder_t *this_gen, uint8_t *buf, int len )
-{
- //lprintf( "sequence_header_advanced\n" );
- sequence_t *sequence = (sequence_t*)&this_gen->sequence;
-
- if ( len < 5 )
- return;
-
- sequence->profile = PROFILE_VC1_ADVANCED;
- //lprintf("PROFILE_VC1_ADVANCED\n");
- bits_reader_set( &sequence->br, buf );
- read_bits( &sequence->br, 16 );
- sequence->coded_width = read_bits( &sequence->br, 12 )<<1;
- sequence->coded_height = (read_bits( &sequence->br, 12 )+1)<<1;
- read_bits( &sequence->br, 1 );
- sequence->picture.interlace = read_bits( &sequence->br, 1 );
- read_bits( &sequence->br, 1 );
- sequence->picture.finterpflag = read_bits( &sequence->br, 1 );
- read_bits( &sequence->br, 2 );
- sequence->picture.maxbframes = 7;
-
- sequence->have_header = 1;
-}
-
-static void sequence_header( crystalhd_vc1_decoder_t *this_gen, uint8_t *buf, int len )
-{
- //lprintf( "sequence_header\n" );
- sequence_t *sequence = (sequence_t*)&this_gen->sequence;
-
- if ( len < 4 )
- return;
-
- bits_reader_set( &sequence->br, buf );
- switch ( read_bits( &sequence->br, 2 ) ) {
- case 0: sequence->profile = PROFILE_VC1_SIMPLE; lprintf("PROFILE_VC1_SIMPLE\n"); break;
- case 1: sequence->profile = PROFILE_VC1_MAIN; lprintf("PROFILE_VC1_MAIN\n"); break;
- case 2: sequence->profile = PROFILE_VC1_MAIN; lprintf("vc1_complex profile not supported by vdpau, trying vc1_main.\n"); break;
- case 3: return sequence_header_advanced( this_gen, buf, len ); break;
- default: return; /* illegal value, broken header? */
- }
- read_bits( &sequence->br, 22 );
- sequence->picture.rangered = read_bits( &sequence->br, 1 );
- sequence->picture.maxbframes = read_bits( &sequence->br, 3 );
- read_bits( &sequence->br, 2 );
- sequence->picture.finterpflag = read_bits( &sequence->br, 1 );
-
- sequence->have_header = 1;
-}
-
-static void picture_header( crystalhd_vc1_decoder_t *this_gen, uint8_t *buf, int len )
-{
- sequence_t *sequence = (sequence_t*)&this_gen->sequence;
- picture_t *pic = (picture_t*)&sequence->picture;
- int tmp;
-
- lprintf("picture_header\n");
-
- bits_reader_set( &sequence->br, buf );
- read_bits( &sequence->br, 2 );
-
- if ( pic->finterpflag )
- read_bits( &sequence->br, 1 );
- if ( pic->rangered ) {
- pic->rangered = (read_bits( &sequence->br, 1 ) << 1) +1;
- }
- if ( !pic->maxbframes ) {
- if ( read_bits( &sequence->br, 1 ) )
- pic->picture_type = P_FRAME;
- else
- pic->picture_type = I_FRAME;
- }
- else {
- if ( read_bits( &sequence->br, 1 ) )
- pic->picture_type = P_FRAME;
- else {
- if ( read_bits( &sequence->br, 1 ) )
- pic->picture_type = I_FRAME;
- else
- pic->picture_type = B_FRAME;
- }
- }
- if ( pic->picture_type == B_FRAME ) {
- tmp = read_bits( &sequence->br, 3 );
- if ( tmp==7 ) {
- tmp = (tmp<<4) | read_bits( &sequence->br, 4 );
- if ( tmp==127 )
- pic->picture_type = BI_FRAME;
- }
- }
-}
-
-static void picture_header_advanced( crystalhd_vc1_decoder_t *this_gen, uint8_t *buf, int len )
-{
- sequence_t *sequence = (sequence_t*)&this_gen->sequence;
- picture_t *pic = (picture_t*)&sequence->picture;
-
- //lprintf("picture_header_advanced\n");
-
- bits_reader_set( &sequence->br, buf );
-
- if ( pic->interlace ) {
- //lprintf("frame->interlace=1\n");
- if ( !read_bits( &sequence->br, 1 ) ) {
- lprintf("progressive frame\n");
- pic->frame_coding_mode = PICTURE_FRAME;
- }
- else {
- if ( !read_bits( &sequence->br, 1 ) ) {
- //lprintf("frame interlaced\n");
- pic->frame_coding_mode = PICTURE_FRAME_INTERLACE;
- }
- else {
- //lprintf("field interlaced\n");
- pic->frame_coding_mode = PICTURE_FIELD_INTERLACE;
- }
- }
- }
- if ( pic->interlace && pic->frame_coding_mode == PICTURE_FIELD_INTERLACE ) {
- pic->fptype = read_bits( &sequence->br, 3 );
- switch ( pic->fptype ) {
- case FIELDS_I_I:
- case FIELDS_I_P:
- pic->picture_type = I_FRAME; break;
- case FIELDS_P_I:
- case FIELDS_P_P:
- pic->picture_type = P_FRAME; break;
- case FIELDS_B_B:
- case FIELDS_B_BI:
- pic->picture_type = B_FRAME; break;
- default:
- pic->picture_type = BI_FRAME;
- }
- } else {
- if ( !read_bits( &sequence->br, 1 ) )
- pic->picture_type = P_FRAME;
- else {
- if ( !read_bits( &sequence->br, 1 ) )
- pic->picture_type = B_FRAME;
- else {
- if ( !read_bits( &sequence->br, 1 ) )
- pic->picture_type = I_FRAME;
- else {
- if ( !read_bits( &sequence->br, 1 ) )
- pic->picture_type = BI_FRAME;
- else {
- pic->picture_type = P_FRAME;
- pic->skipped = 1;
- }
- }
- }
- }
- }
-}
-
-static void parse_header( crystalhd_vc1_decoder_t *this_gen, uint8_t *buf, int len ) {
- sequence_t *sequence = (sequence_t*)&this_gen->sequence;
- int off=0;
-
- while ( off < (len-4) ) {
- uint8_t *buffer = buf+off;
- if ( buffer[0]==0 && buffer[1]==0 && buffer[2]==1 ) {
- switch ( buffer[3] ) {
- case sequence_header_code:
- sequence_header( this_gen, buf+off+4, len-off-4 );
- break;
- }
- }
- ++off;
- }
- if ( !sequence->have_header ) {
- sequence_header( this_gen, buf, len );
- }
-}
-
-static void remove_emulation_prevention( uint8_t *src, uint8_t *dst, int src_len, int *dst_len )
-{
- int i;
- int len = 0;
- int removed = 0;
-
- for ( i=0; i<src_len-3; ++i ) {
- if ( src[i]==0 && src[i+1]==0 && src[i+2]==3 ) {
- //lprintf("removed emulation prevention byte\n");
- dst[len++] = src[i];
- dst[len++] = src[i+1];
- i += 2;
- ++removed;
- }
- else {
- memcpy( dst+len, src+i, 4 );
- ++len;
- }
- }
- for ( ; i<src_len; ++i )
- dst[len++] = src[i];
- *dst_len = src_len-removed;
-}
-
-static int parse_code( crystalhd_vc1_decoder_t *this_gen, uint8_t *buf, int len )
-{
- sequence_t *sequence = (sequence_t*)&this_gen->sequence;
-
- if ( !sequence->have_header && buf[3]!=sequence_header_code )
- return 0;
-
- if ( sequence->code_start == frame_start_code ) {
- if ( sequence->current_code==field_start_code || sequence->current_code==slice_start_code ) {
- return -1;
- }
- return 1; /* frame complete, decode */
- }
-
- switch ( buf[3] ) {
- int dst_len;
- uint8_t *tmp;
- case sequence_header_code:
- //lprintf("sequence_header_code\n");
- tmp = malloc( len );
- remove_emulation_prevention( buf, tmp, len, &dst_len );
- sequence_header( this_gen, tmp+4, dst_len-4 );
- free( tmp );
- break;
- case entry_point_code:
- //lprintf("entry_point_code\n");
- tmp = malloc( len );
- remove_emulation_prevention( buf, tmp, len, &dst_len );
- free( tmp );
- break;
- case sequence_end_code:
- //lprintf("sequence_end_code\n");
- break;
- case frame_start_code:
- //lprintf("frame_start_code, len=%d\n", len);
- break;
- case field_start_code:
- //lprintf("field_start_code\n");
- break;
- case slice_start_code:
- //lprintf("slice_start_code, len=%d\n", len);
- break;
- }
- return 0;
-}
-
-/*
-static int search_field( crystalhd_vc1_decoder_t *vd, uint8_t *buf, int len )
-{
- int i;
- lprintf("search_fields, len=%d\n", len);
- for ( i=0; i<len-4; ++i ) {
- if ( buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==field_start_code ) {
- lprintf("found field_start_code at %d\n", i);
- return i;
- }
- }
- return 0;
-}
-*/
-
-static void decode_picture( crystalhd_vc1_decoder_t *vd, buf_element_t *bufelem)
-{
- sequence_t *seq = (sequence_t*)&vd->sequence;
- picture_t *pic = (picture_t*)&seq->picture;
-
- uint8_t *buf;
- int len;
-
- pic->skipped = 0;
- pic->field = 0;
-
- if ( seq->mode == MODE_FRAME ) {
- buf = seq->buf;
- len = seq->bufpos;
- if ( seq->profile==PROFILE_VC1_ADVANCED )
- picture_header_advanced( vd, buf, len );
- else
- picture_header( vd, buf, len );
-
- if ( len < 2 )
- pic->skipped = 1;
- } else {
- buf = seq->buf+seq->start+4;
- len = seq->bufseek-seq->start-4;
- if ( seq->profile==PROFILE_VC1_ADVANCED ) {
- int tmplen = (len>50) ? 50 : len;
- uint8_t *tmp = malloc( tmplen );
- remove_emulation_prevention( buf, tmp, tmplen, &tmplen );
- picture_header_advanced( vd, tmp, tmplen );
- free( tmp );
- }
- else
- picture_header( vd, buf, len );
-
- if ( len < 2 )
- pic->skipped = 1;
- }
-
- /*
- if ( pic->skipped )
- pic->picture_type = P_FRAME;
- */
-
- if(pic->skipped) {
- reset_picture( &seq->picture );
- return;
- }
-
- seq->seq_pts +=seq->video_step;
- reset_picture( &seq->picture );
-}
-
-
-/*
- * This function receives a buffer of data from the demuxer layer and
- * figures out how to handle it based on its header flags.
- */
-static void crystalhd_vc1_decode_data (video_decoder_t *this_gen,
- buf_element_t *buf) {
-
- crystalhd_vc1_decoder_t *this = (crystalhd_vc1_decoder_t *) this_gen;
- sequence_t *seq = (sequence_t*)&this->sequence;
-
- if (buf->decoder_flags & BUF_FLAG_PREVIEW) {
- return;
- }
-
- if (buf->decoder_flags & BUF_FLAG_FRAMERATE) {
- //lprintf("BUF_FLAG_FRAMERATE=%d\n", buf->decoder_info[0]);
- if ( buf->decoder_info[0] > 0 ) {
- this->video_step = buf->decoder_info[0];
- _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step);
- }
- }
-
- if (buf->decoder_flags & BUF_FLAG_ASPECT) {
- this->ratio = (double)buf->decoder_info[1]/(double)buf->decoder_info[2];
- //lprintf("arx=%d ary=%d ratio=%f\n", buf->decoder_info[1], buf->decoder_info[2], this->ratio);
- }
-
- if (buf->decoder_flags & BUF_FLAG_FRAME_START) {
- //lprintf("BUF_FLAG_FRAME_START\n");
- seq->seq_pts = buf->pts;
- }
-
- if ( !buf->size )
- return;
-
- seq->cur_pts = buf->pts;
-
- if(buf->decoder_flags & BUF_FLAG_STDHEADER) {
- //lprintf("BUF_FLAG_STDHEADER\n");
- xine_bmiheader *bih = (xine_bmiheader *) buf->content;
- int bs = sizeof( xine_bmiheader );
- this->width = bih->biWidth;
- this->height = bih->biHeight;
- //lprintf( "width=%d height=%d\n", bih->biWidth, bih->biHeight );
- this->start_decoding = 1;
- if ( buf->size > bs ) {
- seq->mode = MODE_FRAME;
- parse_header( this, buf->content+bs, buf->size-bs );
- }
- return;
- }
-
- int size = seq->bufpos+buf->size;
- if ( seq->bufsize < size ) {
- seq->bufsize = size+10000;
- seq->buf = realloc( seq->buf, seq->bufsize );
- //lprintf("sequence buffer realloced = %d\n", seq->bufsize );
- }
- xine_fast_memcpy( seq->buf+seq->bufpos, buf->content, buf->size );
- seq->bufpos += buf->size;
-
- if ( seq->mode == MODE_FRAME ) {
- if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
- //lprintf("BUF_FLAG_FRAME_END\n");
-
- //crystalhd_decode_package( seq->buf, 4);
- this->start_decoding = 1;
- crystalhd_vc1_handle_buffer( this, buf, seq->buf, seq->bufpos);
-
- decode_picture(this, buf);
- seq->bufpos = 0;
- }
- } else {
- int res;
- while ( seq->bufseek <= seq->bufpos-4 ) {
- uint8_t *buffer = seq->buf+seq->bufseek;
- if ( buffer[0]==0 && buffer[1]==0 && buffer[2]==1 ) {
-
- //crystalhd_decode_package( buffer, 4);
- this->start_decoding = 1;
- crystalhd_vc1_handle_buffer( this, buf, seq->buf+seq->start, seq->bufseek-seq->start);
-
- seq->current_code = buffer[3];
- //lprintf("current_code = %d\n", seq->current_code);
- if ( seq->start<0 ) {
- seq->start = seq->bufseek;
- seq->code_start = buffer[3];