[4] | 1 | /****************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 5 | * University of Illinois at Chicago |
---|
| 6 | * |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright |
---|
| 13 | * notice, this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above |
---|
| 15 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 16 | * in the documentation and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 18 | * the names of its contributors may be used to endorse or promote |
---|
| 19 | * products derived from this software without specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 25 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | * |
---|
| 33 | * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/ |
---|
| 34 | * |
---|
| 35 | *****************************************************************************/ |
---|
| 36 | |
---|
| 37 | #ifndef SVC_DECODE_MPEG2_H |
---|
| 38 | #define SVC_DECODE_MPEG2_H |
---|
| 39 | |
---|
| 40 | #include <stdio.h> |
---|
| 41 | #include <stdlib.h> |
---|
| 42 | #include <string.h> |
---|
| 43 | #include <inttypes.h> |
---|
| 44 | #include "SVC_codecs.h" |
---|
| 45 | extern "C" |
---|
| 46 | { |
---|
| 47 | #include "mpeg2dec/mpeg2.h" |
---|
| 48 | #include "mpeg2dec/mpeg2convert.h" |
---|
| 49 | } |
---|
| 50 | #include "SVC_output_module.h" |
---|
| 51 | //#include "SVC_decode_module.h" |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | #define DEMUX_PAYLOAD_START 1 |
---|
| 55 | #define DEMUX_HEADER 0 |
---|
| 56 | #define DEMUX_DATA 1 |
---|
| 57 | #define DEMUX_SKIP 2 |
---|
| 58 | static int state = DEMUX_SKIP; |
---|
| 59 | static int state_bytes = 0; |
---|
| 60 | static uint8_t head_buf[264]; |
---|
| 61 | static int buffer_size = 188; |
---|
| 62 | |
---|
| 63 | typedef struct { |
---|
| 64 | int (* convert) (int stage, void * id, |
---|
| 65 | const struct mpeg2_sequence_s * sequence, |
---|
| 66 | int stride, uint32_t accel, void * arg, |
---|
| 67 | struct mpeg2_convert_init_s * result); |
---|
| 68 | } vo_setup_result_t; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | class SVC_decode_mpeg2 |
---|
| 72 | { |
---|
| 73 | public: |
---|
| 74 | SVC_decode_mpeg2(); |
---|
| 75 | void init(int program_id, int color_mode, int buf_size, char* output_addr, int output_port); |
---|
| 76 | void set_output_callback(void* output_obj, DECODEOUTPUT_CALLBACK callback); |
---|
| 77 | void decode (unsigned char* input_data, int input_size); |
---|
| 78 | static void * malloc_hook (unsigned size, mpeg2_alloc_t reason); |
---|
| 79 | void mpeg2_initialization(); |
---|
| 80 | void set_output_module(SVC_output_module* o_module); |
---|
| 81 | void stop(); |
---|
| 82 | int demux (uint8_t * buf, uint8_t * end, int flags); |
---|
| 83 | void decode_mpeg2 (uint8_t * current, uint8_t * end); |
---|
| 84 | int output_setup (unsigned int width, |
---|
| 85 | unsigned int height, unsigned int chroma_width, |
---|
| 86 | unsigned int chroma_height); |
---|
| 87 | private: |
---|
| 88 | int m_byte_pixel; |
---|
| 89 | int demux_pid; |
---|
| 90 | int demux_track; |
---|
| 91 | int m_color_mode; |
---|
| 92 | int total_offset; |
---|
| 93 | mpeg2dec_t * mpeg2dec; |
---|
| 94 | vo_setup_result_t m_convert_result; |
---|
| 95 | DECODEOUTPUT_CALLBACK m_output_callback; |
---|
| 96 | void * m_output_obj; |
---|
| 97 | SVC_output_module * m_output_module; |
---|
| 98 | char* m_output_addr; |
---|
| 99 | int m_output_port; |
---|
| 100 | |
---|
| 101 | //decoded image information |
---|
| 102 | unsigned int m_width; |
---|
| 103 | unsigned int m_height; |
---|
| 104 | unsigned int m_chroma_width; |
---|
| 105 | unsigned int m_chroma_height; |
---|
| 106 | unsigned char * fbuf[3][3]; |
---|
| 107 | |
---|
| 108 | uint8_t * buffer; |
---|
| 109 | uint8_t * buf; |
---|
| 110 | uint8_t * nextbuf; |
---|
| 111 | uint8_t * data; |
---|
| 112 | uint8_t * end; |
---|
| 113 | }; |
---|
| 114 | #endif |
---|
| 115 | |
---|