[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 | #include "SVC_input_null.h" |
---|
| 38 | |
---|
| 39 | SVC_input_null::SVC_input_null() |
---|
| 40 | { |
---|
| 41 | m_pid = 69; |
---|
| 42 | m_byte_pixel = 2; |
---|
| 43 | m_color_mode = RGB16; |
---|
| 44 | m_decode_mpeg2 = NULL; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void SVC_input_null::setOutput(SVC_output_module *o_module) |
---|
| 48 | { |
---|
| 49 | m_output_module = o_module; |
---|
| 50 | if(m_decode_mpeg2) |
---|
| 51 | m_decode_mpeg2 -> set_output_module(m_output_module); |
---|
| 52 | if(m_codec == UNCOM) |
---|
| 53 | m_output_module ->init (m_buffer_size,1,0,m_output_addr,m_output_port); |
---|
| 54 | } |
---|
| 55 | void SVC_input_null::init(int codec,int color_mode, int buffer_size, int rtp_flag, char* addr, int port, char* output_addr, int output_port) |
---|
| 56 | { |
---|
| 57 | //setting network configuration |
---|
| 58 | m_input_addr = addr; |
---|
| 59 | m_input_port = port; |
---|
| 60 | m_output_addr = output_addr; |
---|
| 61 | m_output_port = output_port; |
---|
| 62 | m_color_mode = color_mode; |
---|
| 63 | m_codec = codec; |
---|
| 64 | m_byte_pixel = convert_format2pixelbyte(m_color_mode); |
---|
| 65 | m_buffer_size = buffer_size; |
---|
| 66 | |
---|
| 67 | //setting decoder configuration |
---|
| 68 | select_decoder(codec); |
---|
| 69 | } |
---|
| 70 | void SVC_input_null::run() |
---|
| 71 | { |
---|
| 72 | m_receive_callback((void*)this); //process for specific decoder |
---|
| 73 | } |
---|
| 74 | void SVC_input_null::select_decoder(int codec) |
---|
| 75 | { |
---|
| 76 | switch(codec) |
---|
| 77 | { |
---|
| 78 | case MPEG2: |
---|
| 79 | /* setting capture callback function */ |
---|
| 80 | m_receive_callback = mpeg2_receive; |
---|
| 81 | fprintf(stderr,"CODEC:MPEG2\n"); |
---|
| 82 | /* setting decoder */ |
---|
| 83 | m_decode_mpeg2 = new SVC_decode_mpeg2(); |
---|
| 84 | m_decode_mpeg2 -> init(m_pid, m_color_mode,m_buffer_size,m_output_addr,m_output_port); |
---|
| 85 | m_decode_mpeg2 -> set_output_callback((void*)this, decode_output_callback); |
---|
| 86 | |
---|
| 87 | break; |
---|
| 88 | case DV: |
---|
| 89 | /* setting capture callback function */ |
---|
| 90 | m_receive_callback = dv_receive; |
---|
| 91 | fprintf(stderr,"CODEC:DV\n"); |
---|
| 92 | |
---|
| 93 | /* setting decoder */ |
---|
| 94 | |
---|
| 95 | break; |
---|
| 96 | case UNCOM: |
---|
| 97 | m_receive_callback = mpeg2_receive; |
---|
| 98 | /* setting capture callback function */ |
---|
| 99 | fprintf(stderr,"CODEC:NULL\n"); |
---|
| 100 | /* setting decoder */ |
---|
| 101 | |
---|
| 102 | break; |
---|
| 103 | |
---|
| 104 | default: |
---|
| 105 | fprintf(stderr,"This codec is not supported\n"); |
---|
| 106 | break; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void SVC_input_null::decode_output_callback(void* output_obj, uint8_t * const * buf, void * id, int width, int height) |
---|
| 111 | { |
---|
| 112 | SVC_input_null* THIS = (SVC_input_null*) output_obj; |
---|
| 113 | THIS -> set_imagesize(width, height); |
---|
| 114 | THIS -> decode_ouput(buf); |
---|
| 115 | } |
---|
| 116 | void SVC_input_null::decode_ouput(uint8_t * const * buf) |
---|
| 117 | { |
---|
| 118 | m_output_module -> push_data((unsigned char*)buf[0],m_width,m_height,m_byte_pixel); |
---|
| 119 | } |
---|
| 120 | void SVC_input_null::set_imagesize (int width, int height) |
---|
| 121 | { |
---|
| 122 | m_width = width; |
---|
| 123 | m_height = height; |
---|
| 124 | } |
---|
| 125 | char* SVC_input_null::get_input_addr() |
---|
| 126 | { |
---|
| 127 | return m_input_addr; |
---|
| 128 | } |
---|
| 129 | int SVC_input_null::get_input_port() |
---|
| 130 | { |
---|
| 131 | return m_input_port; |
---|
| 132 | } |
---|
| 133 | int SVC_input_null::get_buffer_size() |
---|
| 134 | { |
---|
| 135 | return m_buffer_size; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | void SVC_input_null::mpeg2_receive(void* obj) |
---|
| 139 | { |
---|
| 140 | SVC_input_null* THIS = (SVC_input_null *)obj; |
---|
| 141 | |
---|
| 142 | int fd =0; //stdin |
---|
| 143 | struct timeval tv; |
---|
| 144 | fd_set rfds; |
---|
| 145 | int result = 0; |
---|
| 146 | int buf_size = THIS -> get_buffer_size(); |
---|
| 147 | char* stream = (char*) malloc(sizeof(char)*SVC_MAX_INPUTNET_BUFFER_SIZE); |
---|
| 148 | |
---|
| 149 | fprintf (stderr, "Starting to receive input_null\n"); |
---|
| 150 | int total = 0; |
---|
| 151 | |
---|
| 152 | do { |
---|
| 153 | FD_ZERO (&rfds); |
---|
| 154 | FD_SET (fd, &rfds); |
---|
| 155 | tv.tv_sec = 0; |
---|
| 156 | tv.tv_usec = 20000; |
---|
| 157 | |
---|
| 158 | if (select (fd + 1, &rfds, NULL, NULL, &tv) > 0) //if data is received |
---|
| 159 | { |
---|
| 160 | sleep(0); |
---|
| 161 | if(FD_ISSET(fd, &rfds)) |
---|
| 162 | { |
---|
| 163 | //read data from standard input |
---|
| 164 | result = fread(stream,1,buf_size,stdin); |
---|
| 165 | |
---|
| 166 | if(result == buf_size) |
---|
| 167 | { |
---|
| 168 | //fprintf(stderr, "SVC_input_null::read data %d\n",result); |
---|
| 169 | //forward data received from stdin to decode |
---|
| 170 | if(THIS-> m_codec != UNCOM) |
---|
| 171 | THIS -> m_decode_mpeg2 -> decode((unsigned char*)stream,result); |
---|
| 172 | else |
---|
| 173 | THIS -> m_output_module -> push_data((unsigned char*)stream,result,1,1); |
---|
| 174 | |
---|
| 175 | total += result; |
---|
| 176 | if (total > 7800) // 6 packets == 1 frame ?? |
---|
| 177 | { |
---|
| 178 | //usleep((int)(1000.0/30.0)*1000); // get 30fps |
---|
| 179 | usleep(1); |
---|
| 180 | total = 0; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | } |
---|
| 185 | else { |
---|
| 186 | fprintf(stderr, "SVC_input_null::incorrect received byte size %d -> %d received\n",buf_size,result); |
---|
| 187 | break; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | else |
---|
| 191 | fprintf(stderr, "SVC_input_null::other's data\n"); |
---|
| 192 | |
---|
| 193 | } |
---|
| 194 | else |
---|
| 195 | { |
---|
| 196 | //fprintf(stderr, "SVC_input_null::no data\n"); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | }while (g_done_control == 0 || result == 0); //should check |
---|
| 201 | |
---|
| 202 | free(stream); |
---|
| 203 | |
---|
| 204 | fprintf (stderr, "input_null is done.\n"); |
---|
| 205 | } |
---|
| 206 | void SVC_input_null::dv_receive(void* obj) |
---|
| 207 | { |
---|
| 208 | SVC_input_null* THIS = (SVC_input_null *)obj; |
---|
| 209 | |
---|
| 210 | } |
---|