void init_car(){ init_motor(); init_motor_CWCCW(); init_encoder(); init_External_Interrupt(); init_linear_actuator(); init_Neural(&n_r, 0.01, 0.01, 0); init_Neural(&n_l, 0.01, 0.01, 0); init_Neural(&n_r_back, 0.01, 0.01, 0); init_Neural(&n_l_back, 0.01, 0.01, 0); array_1d_Init_2(RECORD_SIZE, 0, path_record_r_p); array_1d_Init_2(RECORD_SIZE, 0, path_record_l_p); array_1d_Init_2(RECORD_SIZE, 0, path_record_r_n); array_1d_Init_2(RECORD_SIZE, 0, path_record_l_n); array_1d_Init_2(RECORD_SIZE, 0, kp_record_l); array_1d_Init_2(RECORD_SIZE, 0, kp_record_r); array_1d_Init_2(RECORD_SIZE, 0, ki_record_l); array_1d_Init_2(RECORD_SIZE, 0, ki_record_r); array_1d_Init_2(RECORD_SIZE, 0, kd_record_l); array_1d_Init_2(RECORD_SIZE, 0, kd_record_r); array_1d_Init_2(RECORD_SIZE, 0, desire_record); array_1d_Init_2(RECORD_SIZE, 0, c_out_r); array_1d_Init_2(RECORD_SIZE, 0, c_out_l); path_counter = 0; carTimers = xTimerCreate("Car_State_Polling", ( CAR_POLLING_PERIOD), pdTRUE, ( void * ) 1, Car_State_Polling ); xTimerStart( carTimers, 0 ); }
////////////////////////////////////////////////////////////////////////////// /// Inizialization. This function is called once before entering /// main loop. /// ////////////////////////////////////////////////////////////////////////////// void init() { VMC_INT_16 motorID; init_aisc167b(); init_asccom(); init_cycletime_counter(); i2c_init(); init_bioport(); if (can_init(CAN_BAUD, 0)) while(1){led_swap_green();} led_set_green(0); led_set_red(0); ledseq_init(); ais_system_init(); //init_Thermic(); init_error(); init_calculatestate(); init_motorcontrol(); init_controller(); init_current_limiter(); mpwr_init(); set_default_configuration(); for (motorID = 0; motorID < 3; motorID++) { // init_Limiter(i, 100); init_encoder(motorID); } }
void v4l2_init(struct camera *cam) { open_camera(cam); init_camera(cam); start_capturing(cam); init_encoder(cam); init_file(); }
main() { int i,n,m; init_IPIC(); ip = (IP_STEPPER*)IPABase; init_stepper(); init_encoder(); // ip->AxisCtrl1.Polarity = 0; ip->AxisCtrl1.Source = 0; ip->SyncCtrl = 0; ip->intVector = 0xF0; //programmer timer MCchip : une it toutes les TICK mili secondes StoreByte(MCchip_Base + General_Control_R, 0x2); /* MIEN */ StoreByte(MCchip_Base+Timer1_Control_R, 3); /* CEN COC */ StoreLong(MCchip_Base+Timer1_Compare_R, TICK*1000); StoreByte(MCchip_Base+Timer1_Interrupt_R, 0x11); /* IEN IL=1 */ SetHandler(((IVBR+Timer1_IRQ)*4 + VBR), it_timer ); sti(); //start ip->Motor1.csr = START_STOP_CMD | START_MOTION | FH1_SPEED | RAMP_UP_SPEED; while(1) stop(); }
static struct obs_encoder *create_encoder(const char *id, enum obs_encoder_type type, const char *name, obs_data_t *settings, size_t mixer_idx, obs_data_t *hotkey_data) { struct obs_encoder *encoder; struct obs_encoder_info *ei = find_encoder(id); bool success; if (!ei || ei->type != type) return NULL; encoder = bzalloc(sizeof(struct obs_encoder)); encoder->info = *ei; encoder->mixer_idx = mixer_idx; success = init_encoder(encoder, name, settings, hotkey_data); if (!success) { obs_encoder_destroy(encoder); encoder = NULL; } encoder->control = bzalloc(sizeof(obs_weak_encoder_t)); encoder->control->encoder = encoder; obs_context_data_insert(&encoder->context, &obs->data.encoders_mutex, &obs->data.first_encoder); blog(LOG_INFO, "encoder '%s' (%s) created", name, id); return encoder; }
static struct obs_encoder *create_encoder(const char *id, enum obs_encoder_type type, const char *name, obs_data_t settings) { struct obs_encoder *encoder; struct obs_encoder_info *ei = get_encoder_info(id); bool success; if (!ei || ei->type != type) return NULL; encoder = bzalloc(sizeof(struct obs_encoder)); encoder->info = *ei; success = init_encoder(encoder, name, settings); if (!success) { obs_encoder_destroy(encoder); encoder = NULL; } obs_context_data_insert(&encoder->context, &obs->data.encoders_mutex, &obs->data.first_encoder); return encoder; }
void RCE_Sender::cb(rce::ClientPtr client) { init_producer(); init_encoder(); init_sender(); mainloop(); }
int main() { printf("starting test\n"); FILE* input = fopen("screenshot.bin", "rb"); if(input == NULL) { printf("Couldn't find file\n"); exit(1); } encoder_context* context = create_context(); init_encoder(context, 1366, 768); init_codec(context); init_image(context); struct stat stat_info; int result = stat("screenshot.bin", &stat_info); if(result) { fatal("Could not fstat"); } char* buffer = malloc(stat_info.st_size); fread(buffer, stat_info.st_size, 1, input); /* memset(buffer, 0xF, stat_info.st_size); int a; for(a = 0; a < stat_info.st_size; a++) { if(a % 4 == 0) { buffer[a] = 0x0; } }*/ convert_frame(context, buffer); FILE* output = fopen("mem.bin", "wb"); fwrite(context->raw->planes[2], 100000, 1, output); fflush(output); printf("Size is %d\n", context->raw->stride[3]); int i; for(i = 0; i < 100; i++) { convert_frame(context, buffer); encode_next_frame(context); } encode_finish(context); printf("Finished test\n"); }
void encoder() { init_encoder(); /* Adapter runs in the background while the real coder is invoked */ /* as software (user) interrupt routine */ encoder_done = 0; while(! encoder_done) adapt_frame(); }
static void reset_codec_encoder(switch_codec_t *codec) { vpx_context_t *context = (vpx_context_t *)codec->private_info; if (context->encoder_init) { vpx_codec_destroy(&context->encoder); } context->last_ts = 0; context->last_ms = 0; context->framecount = 0; context->encoder_init = 0; context->pkt = NULL; init_encoder(codec); }
/* encoder - decoder cbr or cq ppinloop rebuild.yuv size.txt ssim.txt */ void run_codec_test(char argc, char** argv) { CX264Encoder e; set_default_cmd(); parse_cmd_enc( argc, argv); if(1==verfy_cmd()) { cmd_help(); } init_encoder( &e ); encoder( &e, &gCmd); }
void encoder() { int vnum,i; init_encoder(); for(i=0; i<QSIZE; i++) thequeue[i]=0; for(vnum=0; read_sound_buffer(IDIM, thequeue + (vnum * IDIM)%QSIZE) > 0; vnum++) { vector_end = thequeue+(vnum*IDIM)%QSIZE+IDIM; encode_vector(0); adapt_frame(); } }
int main(void) { short out; int resp; init_mcu(); delay_ms(1000); // printf("Iniciando Encoder\n\r"); resp = init_encoder(1); // printf("Responsta: %u", resp); while (TRUE) ; return 0; }
int main() { // capture any reset reason G_reset_source = MCUSR; // clear the status register by writing ones // (odd, I know, but that is how it is done) MCUSR = 0x1F; // Display on the LCD that serial connection is needed print("Waiting for"); lcd_goto_xy(0, 1); print(" serial conn..."); // This init will block if no serial connection present // so user sees message on LCD to make a connection init_interface(); // Display the user interface over the serial usb // connection serial_check(); print_reset_reason(); print_usb("Welcome to lab 3!\r\n", 19); print_usage(); print_prompt(); // clear "Waiting for connection" message from the LCD clear(); // turn on interrupts sei(); init_motor(); init_encoder(); // set controller for 1000 Hz init_controller_w_rate(50); while (1) { serial_check(); check_for_new_bytes_received(); } return 0; }
int main(void) { AVCodec *enc = NULL, *dec = NULL; AVCodecContext *enc_ctx = NULL, *dec_ctx = NULL; uint64_t channel_layouts[] = {AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT1_BACK, AV_CH_LAYOUT_SURROUND, AV_CH_LAYOUT_STEREO_DOWNMIX}; int sample_rates[] = {8000, 44100, 48000, 192000}; int cl, sr; avcodec_register_all(); enc = avcodec_find_encoder(AV_CODEC_ID_FLAC); if (!enc) { av_log(NULL, AV_LOG_ERROR, "Can't find encoder\n"); return 1; } dec = avcodec_find_decoder(AV_CODEC_ID_FLAC); if (!dec) { av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n"); return 1; } for (cl = 0; cl < FF_ARRAY_ELEMS(channel_layouts); cl++) { for (sr = 0; sr < FF_ARRAY_ELEMS(sample_rates); sr++) { if (init_encoder(enc, &enc_ctx, channel_layouts[cl], sample_rates[sr]) != 0) return 1; if (init_decoder(dec, &dec_ctx, channel_layouts[cl]) != 0) return 1; if (run_test(enc, dec, enc_ctx, dec_ctx) != 0) return 1; close_encoder(&enc_ctx); close_decoder(&dec_ctx); } } return 0; }
static struct obs_encoder *create_encoder(const char *id, enum obs_encoder_type type, const char *name, obs_data_t *settings, size_t mixer_idx, obs_data_t *hotkey_data) { struct obs_encoder *encoder; struct obs_encoder_info *ei = find_encoder(id); bool success; if (ei && ei->type != type) return NULL; encoder = bzalloc(sizeof(struct obs_encoder)); encoder->mixer_idx = mixer_idx; if (!ei) { blog(LOG_ERROR, "Encoder ID '%s' not found", id); encoder->info.id = bstrdup(id); encoder->info.type = type; encoder->owns_info_id = true; } else { encoder->info = *ei; } success = init_encoder(encoder, name, settings, hotkey_data); if (!success) { blog(LOG_ERROR, "creating encoder '%s' (%s) failed", name, id); obs_encoder_destroy(encoder); return NULL; } encoder->control = bzalloc(sizeof(obs_weak_encoder_t)); encoder->control->encoder = encoder; obs_context_data_insert(&encoder->context, &obs->data.encoders_mutex, &obs->data.first_encoder); blog(LOG_INFO, "encoder '%s' (%s) created", name, id); return encoder; }
void initialize() { /* ---------communication-------- */ init_USART3(9600); USART_puts(USART3,"initial...\n\r"); USART_puts(USART3,"USART is ready\n\r"); /* ------------motors------------ */ init_motor(); init_linear_actuator(); USART_puts(USART3,"motor is ready \n\r"); /* ------------sensor------------ */ init_encoder(); init_CurTransducer(); init_Indicator(); /* -----------SD(data)----------- */ USART_puts(USART3,"test sdio/fat \n\r"); start_record(); USART_puts(USART3,"test end \n\r"); }
extern int main(int argc, char **argv) { // Get the preset number from the command line. uint32_t preset = get_preset(argc, argv); // Initialize a lzma_stream structure. When it is allocated on stack, // it is simplest to use LZMA_STREAM_INIT macro like below. When it // is allocated on heap, using memset(strmptr, 0, sizeof(*strmptr)) // works (as long as NULL pointers are represented with zero bits // as they are on practically all computers today). lzma_stream strm = LZMA_STREAM_INIT; // Initialize the encoder. If it succeeds, compress from // stdin to stdout. bool success = init_encoder(&strm, preset); if (success) success = compress(&strm, stdin, stdout); // Free the memory allocated for the encoder. If we were encoding // multiple files, this would only need to be done after the last // file. See 02_decompress.c for handling of multiple files. // // It is OK to call lzma_end() multiple times or when it hasn't been // actually used except initialized with LZMA_STREAM_INIT. lzma_end(&strm); // Close stdout to catch possible write errors that can occur // when pending data is flushed from the stdio buffers. if (fclose(stdout)) { fprintf(stderr, "Write error: %s\n", strerror(errno)); success = false; } return success ? EXIT_SUCCESS : EXIT_FAILURE; }
PyObject* encoders_encode_alac(PyObject *dummy, PyObject *args, PyObject *keywds) { static char *kwlist[] = {"file", "pcmreader", "block_size", "initial_history", "history_multiplier", "maximum_k", "minimum_interlacing_leftweight", "maximum_interlacing_leftweight", NULL}; PyObject *file_obj; FILE *output_file; BitstreamWriter *output = NULL; pcmreader* pcmreader; struct alac_context encoder; array_ia* channels = array_ia_new(); unsigned frame_file_offset; PyObject *log_output; init_encoder(&encoder); encoder.options.minimum_interlacing_leftweight = 0; encoder.options.maximum_interlacing_leftweight = 4; /*extract a file object, PCMReader-compatible object and encoding options*/ if (!PyArg_ParseTupleAndKeywords( args, keywds, "OO&iiii|ii", kwlist, &file_obj, pcmreader_converter, &pcmreader, &(encoder.options.block_size), &(encoder.options.initial_history), &(encoder.options.history_multiplier), &(encoder.options.maximum_k), &(encoder.options.minimum_interlacing_leftweight), &(encoder.options.maximum_interlacing_leftweight))) return NULL; encoder.bits_per_sample = pcmreader->bits_per_sample; /*determine if the PCMReader is compatible with ALAC*/ if ((pcmreader->bits_per_sample != 16) && (pcmreader->bits_per_sample != 24)) { PyErr_SetString(PyExc_ValueError, "bits per sample must be 16 or 24"); goto error; } /*convert file object to bitstream writer*/ if ((output_file = PyFile_AsFile(file_obj)) == NULL) { PyErr_SetString(PyExc_TypeError, "file must by a concrete file object"); goto error; } else { output = bw_open(output_file, BS_BIG_ENDIAN); bw_add_callback(output, byte_counter, &(encoder.mdat_byte_size)); } #else int ALACEncoder_encode_alac(char *filename, FILE *input, int block_size, int initial_history, int history_multiplier, int maximum_k) { FILE *output_file; BitstreamWriter *output = NULL; pcmreader *pcmreader; struct alac_context encoder; array_ia* channels = array_ia_new(); unsigned frame_file_offset; init_encoder(&encoder); encoder.options.block_size = block_size; encoder.options.initial_history = initial_history; encoder.options.history_multiplier = history_multiplier; encoder.options.maximum_k = maximum_k; encoder.options.minimum_interlacing_leftweight = 0; encoder.options.maximum_interlacing_leftweight = 4; output_file = fopen(filename, "wb"); /*assume CD quality for now*/ pcmreader = open_pcmreader(input, 44100, 2, 0x3, 16, 0, 1); encoder.bits_per_sample = pcmreader->bits_per_sample; /*convert file object to bitstream writer*/ output = bw_open(output_file, BS_BIG_ENDIAN); bw_add_callback(output, byte_counter, &(encoder.mdat_byte_size)); #endif /*write placeholder mdat header*/ output->write(output, 32, 0); output->write_bytes(output, (uint8_t*)"mdat", 4); /*write frames from pcm_reader until empty*/ if (pcmreader->read(pcmreader, encoder.options.block_size, channels)) goto error; while (channels->_[0]->len > 0) { #ifndef STANDALONE Py_BEGIN_ALLOW_THREADS #endif /*log the number of PCM frames in each ALAC frameset*/ encoder.frame_log->_[LOG_SAMPLE_SIZE]->append( encoder.frame_log->_[LOG_SAMPLE_SIZE], channels->_[0]->len); frame_file_offset = encoder.mdat_byte_size; /*log each frameset's starting offset in the mdat atom*/ encoder.frame_log->_[LOG_FILE_OFFSET]->append( encoder.frame_log->_[LOG_FILE_OFFSET], frame_file_offset); write_frameset(output, &encoder, channels); /*log each frame's total size in bytes*/ encoder.frame_log->_[LOG_BYTE_SIZE]->append( encoder.frame_log->_[LOG_BYTE_SIZE], encoder.mdat_byte_size - frame_file_offset); #ifndef STANDALONE Py_END_ALLOW_THREADS #endif if (pcmreader->read(pcmreader, encoder.options.block_size, channels)) goto error; } /*return to header and rewrite it with the actual value*/ bw_pop_callback(output, NULL); fseek(output_file, 0, 0); output->write(output, 32, encoder.mdat_byte_size); /*close and free allocated files/buffers, which varies depending on whether we're running standlone or not*/ #ifndef STANDALONE log_output = alac_log_output(&encoder); pcmreader->del(pcmreader); output->free(output); free_encoder(&encoder); channels->del(channels); return log_output; error: pcmreader->del(pcmreader); output->free(output); free_encoder(&encoder); channels->del(channels); return NULL; }
int main(int argc, char *argv[]) { char *c; struct encoder_ctx enc_ctx[2]; struct cc_subtitle dec_sub; #ifdef ENABLE_FFMPEG void *ffmpeg_ctx = NULL; #endif struct lib_ccx_ctx *ctx; struct lib_cc_decode *dec_ctx = NULL; init_options (&ccx_options); parse_configuration(&ccx_options); parse_parameters (&ccx_options, argc, argv); // Initialize libraries ctx = init_libraries(&ccx_options); dec_ctx = ctx->dec_ctx; // Prepare write structures init_write(&ctx->wbout1,ccx_options.wbout1.filename); init_write(&ctx->wbout2,ccx_options.wbout2.filename); int show_myth_banner = 0; memset (&cea708services[0],0,CCX_DECODERS_708_MAX_SERVICES*sizeof (int)); // Cannot (yet) be moved because it's needed in parse_parameters. memset (&dec_sub, 0,sizeof(dec_sub)); if (ctx->num_input_files==0 && ccx_options.input_source==CCX_DS_FILE) { usage (); fatal (EXIT_NO_INPUT_FILES, "(This help screen was shown because there were no input files)\n"); } if (ctx->num_input_files>1 && ccx_options.live_stream) { fatal(EXIT_TOO_MANY_INPUT_FILES, "Live stream mode accepts only one input file.\n"); } if (ctx->num_input_files && ccx_options.input_source==CCX_DS_NETWORK) { fatal(EXIT_TOO_MANY_INPUT_FILES, "UDP mode is not compatible with input files.\n"); } if (ccx_options.input_source==CCX_DS_NETWORK || ccx_options.input_source==CCX_DS_TCP) { ccx_options.buffer_input=1; // Mandatory, because each datagram must be read complete. } if (ctx->num_input_files && ccx_options.input_source==CCX_DS_TCP) { fatal(EXIT_TOO_MANY_INPUT_FILES, "TCP mode is not compatible with input files.\n"); } if (ctx->num_input_files > 0) { ctx->wbout1.multiple_files = 1; ctx->wbout1.first_input_file = ctx->inputfile[0]; ctx->wbout2.multiple_files = 1; ctx->wbout2.first_input_file = ctx->inputfile[0]; } // teletext page number out of range if ((tlt_config.page != 0) && ((tlt_config.page < 100) || (tlt_config.page > 899))) { fatal (EXIT_NOT_CLASSIFIED, "Teletext page number could not be lower than 100 or higher than 899\n"); } if (ccx_options.output_filename!=NULL) { // Use the given output file name for the field specified by // the -1, -2 switch. If -12 is used, the filename is used for // field 1. if (ccx_options.extract==2) ctx->wbout2.filename=ccx_options.output_filename; else ctx->wbout1.filename=ccx_options.output_filename; } switch (ccx_options.write_format) { case CCX_OF_RAW: ctx->extension = ".raw"; break; case CCX_OF_SRT: ctx->extension = ".srt"; break; case CCX_OF_SAMI: ctx->extension = ".smi"; break; case CCX_OF_SMPTETT: ctx->extension = ".ttml"; break; case CCX_OF_TRANSCRIPT: ctx->extension = ".txt"; break; case CCX_OF_RCWT: ctx->extension = ".bin"; break; case CCX_OF_SPUPNG: ctx->extension = ".xml"; break; case CCX_OF_NULL: ctx->extension = ""; break; case CCX_OF_DVDRAW: ctx->extension = ".dvdraw"; break; default: fatal (CCX_COMMON_EXIT_BUG_BUG, "write_format doesn't have any legal value, this is a bug.\n"); } params_dump(ctx); // default teletext page if (tlt_config.page > 0) { // dec to BCD, magazine pages numbers are in BCD (ETSI 300 706) tlt_config.page = ((tlt_config.page / 100) << 8) | (((tlt_config.page / 10) % 10) << 4) | (tlt_config.page % 10); } if (ctx->auto_stream==CCX_SM_MCPOODLESRAW && ccx_options.write_format==CCX_OF_RAW) { fatal (EXIT_INCOMPATIBLE_PARAMETERS, "-in=raw can only be used if the output is a subtitle file.\n"); } if (ctx->auto_stream==CCX_SM_RCWT && ccx_options.write_format==CCX_OF_RCWT && ccx_options.output_filename==NULL) { fatal (EXIT_INCOMPATIBLE_PARAMETERS, "CCExtractor's binary format can only be used simultaneously for input and\noutput if the output file name is specified given with -o.\n"); } subline = (unsigned char *) malloc (SUBLINESIZE); switch (ccx_options.input_source) { case CCX_DS_FILE: ctx->basefilename = (char *) malloc (strlen (ctx->inputfile[0])+1); break; case CCX_DS_STDIN: ctx->basefilename = (char *) malloc (strlen (ctx->basefilename_for_stdin)+1); break; case CCX_DS_NETWORK: case CCX_DS_TCP: ctx->basefilename = (char *) malloc (strlen (ctx->basefilename_for_network)+1); break; } if (ctx->basefilename == NULL) fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory\n"); switch (ccx_options.input_source) { case CCX_DS_FILE: strcpy (ctx->basefilename, ctx->inputfile[0]); break; case CCX_DS_STDIN: strcpy (ctx->basefilename, ctx->basefilename_for_stdin); break; case CCX_DS_NETWORK: case CCX_DS_TCP: strcpy (ctx->basefilename, ctx->basefilename_for_network); break; } for (c=ctx->basefilename+strlen (ctx->basefilename)-1; ctx->basefilename && *c!='.'; c--) {;} // Get last . if (*c=='.') *c=0; if (ctx->wbout1.filename==NULL) { ctx->wbout1.filename = (char *) malloc (strlen (ctx->basefilename)+3+strlen (ctx->extension)); ctx->wbout1.filename[0]=0; } if (ctx->wbout2.filename==NULL) { ctx->wbout2.filename = (char *) malloc (strlen (ctx->basefilename)+3+strlen (ctx->extension)); ctx->wbout2.filename[0]=0; } if (ctx->buffer == NULL || ctx->pesheaderbuf==NULL || ctx->wbout1.filename == NULL || ctx->wbout2.filename == NULL || subline==NULL || init_file_buffer() ) { fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory\n"); } if (ccx_options.send_to_srv) { connect_to_srv(ccx_options.srv_addr, ccx_options.srv_port, ccx_options.tcp_desc); } if (ccx_options.write_format!=CCX_OF_NULL) { /* # DVD format uses one raw file for both fields, while Broadcast requires 2 */ if (ccx_options.write_format==CCX_OF_DVDRAW) { if (ctx->wbout1.filename[0]==0) { strcpy (ctx->wbout1.filename,ctx->basefilename); strcat (ctx->wbout1.filename,".raw"); } if (ctx->cc_to_stdout) { ctx->wbout1.fh=STDOUT_FILENO; mprint ("Sending captions to stdout.\n"); } else { mprint ("Creating %s\n", ctx->wbout1.filename); ctx->wbout1.fh=open (ctx->wbout1.filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE); if (ctx->wbout1.fh==-1) { fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Failed\n"); } } } else { if (ctx->cc_to_stdout && ccx_options.extract==12) fatal (EXIT_INCOMPATIBLE_PARAMETERS, "You can't extract both fields to stdout at the same time in broadcast mode."); if (ccx_options.write_format == CCX_OF_SPUPNG && ctx->cc_to_stdout) fatal (EXIT_INCOMPATIBLE_PARAMETERS, "You cannot use -out=spupng with -stdout."); if (ccx_options.extract!=2) { if (ctx->cc_to_stdout) { ctx->wbout1.fh=STDOUT_FILENO; mprint ("Sending captions to stdout.\n"); } else if (!ccx_options.send_to_srv) { if (ctx->wbout1.filename[0]==0) { strcpy (ctx->wbout1.filename,ctx->basefilename); if (ccx_options.extract==12) // _1 only added if there's two files strcat (ctx->wbout1.filename,"_1"); strcat (ctx->wbout1.filename,(const char *) ctx->extension); } mprint ("Creating %s\n", ctx->wbout1.filename); ctx->wbout1.fh=open (ctx->wbout1.filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE); if (ctx->wbout1.fh==-1) { fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Failed (errno=%d)\n", errno); } } switch (ccx_options.write_format) { case CCX_OF_RAW: writeraw(BROADCAST_HEADER, sizeof(BROADCAST_HEADER), &ctx->wbout1); break; case CCX_OF_DVDRAW: break; case CCX_OF_RCWT: if (init_encoder(enc_ctx, &ctx->wbout1)) fatal(EXIT_NOT_ENOUGH_MEMORY, "Not enough memory\n"); set_encoder_subs_delay(enc_ctx, ctx->subs_delay); set_encoder_last_displayed_subs_ms(enc_ctx, ctx->last_displayed_subs_ms); set_encoder_startcredits_displayed(enc_ctx, ctx->startcredits_displayed); break; default: if (!ccx_options.no_bom){ if (ccx_options.encoding == CCX_ENC_UTF_8){ // Write BOM writeraw(UTF8_BOM, sizeof(UTF8_BOM), &ctx->wbout1); } if (ccx_options.encoding == CCX_ENC_UNICODE){ // Write BOM writeraw(LITTLE_ENDIAN_BOM, sizeof(LITTLE_ENDIAN_BOM), &ctx->wbout1); } } if (init_encoder(enc_ctx, &ctx->wbout1)){ fatal(EXIT_NOT_ENOUGH_MEMORY, "Not enough memory\n"); } set_encoder_subs_delay(enc_ctx, ctx->subs_delay); set_encoder_last_displayed_subs_ms(enc_ctx, ctx->last_displayed_subs_ms); set_encoder_startcredits_displayed(enc_ctx, ctx->startcredits_displayed); } } if (ccx_options.extract == 12 && ccx_options.write_format != CCX_OF_RAW) mprint (" and \n"); if (ccx_options.extract!=1) { if (ctx->cc_to_stdout) { ctx->wbout1.fh=STDOUT_FILENO; mprint ("Sending captions to stdout.\n"); } else if(ccx_options.write_format == CCX_OF_RAW && ccx_options.extract == 12) { memcpy(&ctx->wbout2, &ctx->wbout1,sizeof(ctx->wbout1)); } else if (!ccx_options.send_to_srv) { if (ctx->wbout2.filename[0]==0) { strcpy (ctx->wbout2.filename,ctx->basefilename); if (ccx_options.extract==12) // _ only added if there's two files strcat (ctx->wbout2.filename,"_2"); strcat (ctx->wbout2.filename,(const char *) ctx->extension); } mprint ("Creating %s\n", ctx->wbout2.filename); ctx->wbout2.fh=open (ctx->wbout2.filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE); if (ctx->wbout2.fh==-1) { fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Failed\n"); } if(ccx_options.write_format == CCX_OF_RAW) writeraw (BROADCAST_HEADER,sizeof (BROADCAST_HEADER),&ctx->wbout2); } switch (ccx_options.write_format) { case CCX_OF_RAW: case CCX_OF_DVDRAW: break; case CCX_OF_RCWT: if( init_encoder(enc_ctx+1,&ctx->wbout2) ) fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory\n"); set_encoder_subs_delay(enc_ctx+1, ctx->subs_delay); set_encoder_last_displayed_subs_ms(enc_ctx+1, ctx->last_displayed_subs_ms); set_encoder_startcredits_displayed(enc_ctx+1, ctx->startcredits_displayed); break; default: if (!ccx_options.no_bom){ if (ccx_options.encoding == CCX_ENC_UTF_8){ // Write BOM writeraw(UTF8_BOM, sizeof(UTF8_BOM), &ctx->wbout2); } if (ccx_options.encoding == CCX_ENC_UNICODE){ // Write BOM writeraw(LITTLE_ENDIAN_BOM, sizeof(LITTLE_ENDIAN_BOM), &ctx->wbout2); } } if (init_encoder(enc_ctx + 1, &ctx->wbout2)){ fatal(EXIT_NOT_ENOUGH_MEMORY, "Not enough memory\n"); } set_encoder_subs_delay(enc_ctx+1, ctx->subs_delay); set_encoder_last_displayed_subs_ms(enc_ctx+1, ctx->last_displayed_subs_ms); set_encoder_startcredits_displayed(enc_ctx+1, ctx->startcredits_displayed); } } } } if (ccx_options.transcript_settings.xds) { if (ccx_options.write_format != CCX_OF_TRANSCRIPT) { ccx_options.transcript_settings.xds = 0; mprint ("Warning: -xds ignored, XDS can only be exported to transcripts at this time.\n"); } } if (ccx_options.teletext_mode == CCX_TXT_IN_USE) // Here, it would mean it was forced by user telxcc_init(ctx); ctx->fh_out_elementarystream = NULL; if (ccx_options.out_elementarystream_filename!=NULL) { if ((ctx->fh_out_elementarystream = fopen (ccx_options.out_elementarystream_filename,"wb"))==NULL) { fatal(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Unable to open clean file: %s\n", ccx_options.out_elementarystream_filename); } } // Initialize HDTV caption buffer init_hdcc(); if (ccx_options.line_terminator_lf) encoded_crlf_length = encode_line(encoded_crlf, (unsigned char *) "\n"); else encoded_crlf_length = encode_line(encoded_crlf, (unsigned char *) "\r\n"); encoded_br_length = encode_line(encoded_br, (unsigned char *) "<br>"); time_t start, final; time(&start); dec_ctx->processed_enough=0; if (ccx_options.binary_concat) { ctx->total_inputsize=gettotalfilessize(ctx); if (ctx->total_inputsize==-1) fatal (EXIT_UNABLE_TO_DETERMINE_FILE_SIZE, "Failed to determine total file size.\n"); } #ifndef _WIN32 signal_ctx = ctx; m_signal(SIGINT, sigint_handler); #endif while (switch_to_next_file(ctx, 0) && !dec_ctx->processed_enough) { prepare_for_new_file(ctx); #ifdef ENABLE_FFMPEG close_input_file(ctx); ffmpeg_ctx = init_ffmpeg(ctx->inputfile[0]); if(ffmpeg_ctx) { do { int ret = 0; unsigned char *bptr = ctx->buffer; int len = ff_get_ccframe(ffmpeg_ctx, bptr, 1024); int cc_count = 0; if(len == AVERROR(EAGAIN)) { continue; } else if(len == AVERROR_EOF) break; else if(len == 0) continue; else if(len < 0 ) { mprint("Error extracting Frame\n"); break; } else cc_count = len/3; ret = process_cc_data(dec_ctx, bptr, cc_count, &dec_sub); if(ret >= 0 && dec_sub.got_output) { encode_sub(enc_ctx, &dec_sub); dec_sub.got_output = 0; } }while(1); continue; } else { mprint ("\rFailed to initialized ffmpeg falling back to legacy\n"); } #endif if (ctx->auto_stream == CCX_SM_AUTODETECT) { detect_stream_type(ctx); switch (ctx->stream_mode) { case CCX_SM_ELEMENTARY_OR_NOT_FOUND: mprint ("\rFile seems to be an elementary stream, enabling ES mode\n"); break; case CCX_SM_TRANSPORT: mprint ("\rFile seems to be a transport stream, enabling TS mode\n"); break; case CCX_SM_PROGRAM: mprint ("\rFile seems to be a program stream, enabling PS mode\n"); break; case CCX_SM_ASF: mprint ("\rFile seems to be an ASF, enabling DVR-MS mode\n"); break; case CCX_SM_WTV: mprint ("\rFile seems to be a WTV, enabling WTV mode\n"); break; case CCX_SM_MCPOODLESRAW: mprint ("\rFile seems to be McPoodle raw data\n"); break; case CCX_SM_RCWT: mprint ("\rFile seems to be a raw caption with time data\n"); break; case CCX_SM_MP4: mprint ("\rFile seems to be a MP4\n"); break; #ifdef WTV_DEBUG case CCX_SM_HEX_DUMP: mprint ("\rFile seems to be an hexadecimal dump\n"); break; #endif case CCX_SM_MYTH: case CCX_SM_AUTODETECT: fatal(CCX_COMMON_EXIT_BUG_BUG, "Cannot be reached!"); break; } } else { ctx->stream_mode=ctx->auto_stream; } /* ----------------------------------------------------------------- MAIN LOOP ----------------------------------------------------------------- */ // The myth loop autodetect will only be used with ES or PS streams switch (ccx_options.auto_myth) { case 0: // Use whatever stream mode says break; case 1: // Force stream mode to myth ctx->stream_mode=CCX_SM_MYTH; break; case 2: // autodetect myth files, but only if it does not conflict with // the current stream mode switch (ctx->stream_mode) { case CCX_SM_ELEMENTARY_OR_NOT_FOUND: case CCX_SM_PROGRAM: if ( detect_myth(ctx) ) { ctx->stream_mode=CCX_SM_MYTH; } break; default: // Keep stream_mode break; } break; } // Disable sync check for raw formats - they have the right timeline. // Also true for bin formats, but -nosync might have created a // broken timeline for debug purposes. // Disable too in MP4, specs doesn't say that there can't be a jump switch (ctx->stream_mode) { case CCX_SM_MCPOODLESRAW: case CCX_SM_RCWT: case CCX_SM_MP4: #ifdef WTV_DEBUG case CCX_SM_HEX_DUMP: #endif ccx_common_timing_settings.disable_sync_check = 1; break; default: break; } switch (ctx->stream_mode) { case CCX_SM_ELEMENTARY_OR_NOT_FOUND: if (!ccx_options.use_gop_as_pts) // If !0 then the user selected something ccx_options.use_gop_as_pts = 1; // Force GOP timing for ES ccx_common_timing_settings.is_elementary_stream = 1; case CCX_SM_TRANSPORT: case CCX_SM_PROGRAM: case CCX_SM_ASF: case CCX_SM_WTV: if (!ccx_options.use_gop_as_pts) // If !0 then the user selected something ccx_options.use_gop_as_pts = 0; mprint ("\rAnalyzing data in general mode\n"); general_loop(ctx, &enc_ctx); break; case CCX_SM_MCPOODLESRAW: mprint ("\rAnalyzing data in McPoodle raw mode\n"); raw_loop(ctx, &enc_ctx); break; case CCX_SM_RCWT: mprint ("\rAnalyzing data in CCExtractor's binary format\n"); rcwt_loop(ctx, &enc_ctx); break; case CCX_SM_MYTH: mprint ("\rAnalyzing data in MythTV mode\n"); show_myth_banner = 1; myth_loop(ctx, &enc_ctx); break; case CCX_SM_MP4: mprint ("\rAnalyzing data with GPAC (MP4 library)\n"); close_input_file(ctx); // No need to have it open. GPAC will do it for us processmp4 (ctx, ctx->inputfile[0],&enc_ctx); break; #ifdef WTV_DEBUG case CCX_SM_HEX_DUMP: close_input_file(ctx); // processhex will open it in text mode processhex (ctx, ctx->inputfile[0]); break; #endif case CCX_SM_AUTODETECT: fatal(CCX_COMMON_EXIT_BUG_BUG, "Cannot be reached!"); break; } mprint("\n"); dbg_print(CCX_DMT_DECODER_608, "\nTime stamps after last caption block was written:\n"); dbg_print(CCX_DMT_DECODER_608, "Last time stamps: PTS: %s (%+2dF) ", print_mstime( (LLONG) (sync_pts/(MPEG_CLOCK_FREQ/1000) +frames_since_ref_time*1000.0/current_fps) ), frames_since_ref_time); dbg_print(CCX_DMT_DECODER_608, "GOP: %s \n", print_mstime(gop_time.ms) ); // Blocks since last PTS/GOP time stamp. dbg_print(CCX_DMT_DECODER_608, "Calc. difference: PTS: %s (%+3lldms incl.) ", print_mstime( (LLONG) ((sync_pts-min_pts)/(MPEG_CLOCK_FREQ/1000) + fts_offset + frames_since_ref_time*1000.0/current_fps)), fts_offset + (LLONG) (frames_since_ref_time*1000.0/current_fps) ); dbg_print(CCX_DMT_DECODER_608, "GOP: %s (%+3dms incl.)\n", print_mstime((LLONG)(gop_time.ms -first_gop_time.ms +get_fts_max()-fts_at_gop_start)), (int)(get_fts_max()-fts_at_gop_start)); // When padding is active the CC block time should be within // 1000/29.97 us of the differences. dbg_print(CCX_DMT_DECODER_608, "Max. FTS: %s (without caption blocks since then)\n", print_mstime(get_fts_max())); if (ctx->stat_hdtv) { mprint ("\rCC type 0: %d (%s)\n", dec_ctx->cc_stats[0], cc_types[0]); mprint ("CC type 1: %d (%s)\n", dec_ctx->cc_stats[1], cc_types[1]); mprint ("CC type 2: %d (%s)\n", dec_ctx->cc_stats[2], cc_types[2]); mprint ("CC type 3: %d (%s)\n", dec_ctx->cc_stats[3], cc_types[3]); } mprint ("\nTotal frames time: %s (%u frames at %.2ffps)\n", print_mstime( (LLONG)(total_frames_count*1000/current_fps) ), total_frames_count, current_fps); if (ctx->total_pulldownframes) mprint ("incl. pulldown frames: %s (%u frames at %.2ffps)\n", print_mstime( (LLONG)(ctx->total_pulldownframes*1000/current_fps) ), ctx->total_pulldownframes, current_fps); if (pts_set >= 1 && min_pts != 0x01FFFFFFFFLL) { LLONG postsyncms = (LLONG) (ctx->frames_since_last_gop*1000/current_fps); mprint ("\nMin PTS: %s\n", print_mstime( min_pts/(MPEG_CLOCK_FREQ/1000) - fts_offset)); if (pts_big_change) mprint ("(Reference clock was reset at some point, Min PTS is approximated)\n"); mprint ("Max PTS: %s\n", print_mstime( sync_pts/(MPEG_CLOCK_FREQ/1000) + postsyncms)); mprint ("Length: %s\n", print_mstime( sync_pts/(MPEG_CLOCK_FREQ/1000) + postsyncms - min_pts/(MPEG_CLOCK_FREQ/1000) + fts_offset )); } // dvr-ms files have invalid GOPs if (gop_time.inited && first_gop_time.inited && ctx->stream_mode != CCX_SM_ASF) { mprint ("\nInitial GOP time: %s\n", print_mstime(first_gop_time.ms)); mprint ("Final GOP time: %s%+3dF\n", print_mstime(gop_time.ms), ctx->frames_since_last_gop); mprint ("Diff. GOP length: %s%+3dF", print_mstime(gop_time.ms - first_gop_time.ms), ctx->frames_since_last_gop); mprint (" (%s)\n", print_mstime(gop_time.ms - first_gop_time.ms +(LLONG) ((ctx->frames_since_last_gop)*1000/29.97)) ); } if (ctx->false_pict_header) mprint ("\nNumber of likely false picture headers (discarded): %d\n",ctx->false_pict_header); if (ctx->stat_numuserheaders) mprint("\nTotal user data fields: %d\n", ctx->stat_numuserheaders); if (ctx->stat_dvdccheaders) mprint("DVD-type user data fields: %d\n", ctx->stat_dvdccheaders); if (ctx->stat_scte20ccheaders) mprint("SCTE-20 type user data fields: %d\n", ctx->stat_scte20ccheaders); if (ctx->stat_replay4000headers) mprint("ReplayTV 4000 user data fields: %d\n", ctx->stat_replay4000headers); if (ctx->stat_replay5000headers) mprint("ReplayTV 5000 user data fields: %d\n", ctx->stat_replay5000headers); if (ctx->stat_hdtv) mprint("HDTV type user data fields: %d\n", ctx->stat_hdtv); if (ctx->stat_dishheaders) mprint("Dish Network user data fields: %d\n", ctx->stat_dishheaders); if (ctx->stat_divicom) { mprint("CEA608/Divicom user data fields: %d\n", ctx->stat_divicom); mprint("\n\nNOTE! The CEA 608 / Divicom standard encoding for closed\n"); mprint("caption is not well understood!\n\n"); mprint("Please submit samples to the developers.\n\n\n"); } // Add one frame as fts_max marks the beginning of the last frame, // but we need the end. fts_global += fts_max + (LLONG) (1000.0/current_fps); // CFS: At least in Hauppage mode, cb_field can be responsible for ALL the // timing (cb_fields having a huge number and fts_now and fts_global being 0 all // the time), so we need to take that into account in fts_global before resetting // counters. if (cb_field1!=0) fts_global += cb_field1*1001/3; else fts_global += cb_field2*1001/3; // Reset counters - This is needed if some captions are still buffered // and need to be written after the last file is processed. cb_field1 = 0; cb_field2 = 0; cb_708 = 0; fts_now = 0; fts_max = 0; } // file loop close_input_file(ctx); if (ctx->fh_out_elementarystream!=NULL) fclose (ctx->fh_out_elementarystream); flushbuffer (ctx, &ctx->wbout1, false); flushbuffer (ctx, &ctx->wbout2, false); prepare_for_new_file (ctx); // To reset counters used by handle_end_of_data() telxcc_close(ctx); if (ctx->wbout1.fh!=-1) { if (ccx_options.write_format==CCX_OF_SMPTETT || ccx_options.write_format==CCX_OF_SAMI || ccx_options.write_format==CCX_OF_SRT || ccx_options.write_format==CCX_OF_TRANSCRIPT || ccx_options.write_format==CCX_OF_SPUPNG ) { handle_end_of_data(dec_ctx->context_cc608_field_1, &dec_sub); if (dec_sub.got_output) { encode_sub(enc_ctx,&dec_sub); dec_sub.got_output = 0; } } else if(ccx_options.write_format==CCX_OF_RCWT) { // Write last header and data writercwtdata (dec_ctx, NULL); } dinit_encoder(enc_ctx); } if (ctx->wbout2.fh!=-1) { if (ccx_options.write_format==CCX_OF_SMPTETT || ccx_options.write_format==CCX_OF_SAMI || ccx_options.write_format==CCX_OF_SRT || ccx_options.write_format==CCX_OF_TRANSCRIPT || ccx_options.write_format==CCX_OF_SPUPNG ) { handle_end_of_data(dec_ctx->context_cc608_field_2, &dec_sub); if (dec_sub.got_output) { encode_sub(enc_ctx,&dec_sub); dec_sub.got_output = 0; } } dinit_encoder(enc_ctx+1); } flushbuffer (ctx, &ctx->wbout1,true); flushbuffer (ctx, &ctx->wbout2,true); time (&final); long proc_time=(long) (final-start); mprint ("\rDone, processing time = %ld seconds\n", proc_time); if (proc_time>0) { LLONG ratio=(get_fts_max()/10)/proc_time; unsigned s1=(unsigned) (ratio/100); unsigned s2=(unsigned) (ratio%100); mprint ("Performance (real length/process time) = %u.%02u\n", s1, s2); } dbg_print(CCX_DMT_708, "The 708 decoder was reset [%d] times.\n",resets_708); if (ccx_options.teletext_mode == CCX_TXT_IN_USE) mprint ( "Teletext decoder: %"PRIu32" packets processed, %"PRIu32" SRT frames written.\n", tlt_packet_counter, tlt_frames_produced); if (dec_ctx->processed_enough) { mprint ("\rNote: Processing was cancelled before all data was processed because\n"); mprint ("\rone or more user-defined limits were reached.\n"); } if (ccblocks_in_avc_lost>0) { mprint ("Total caption blocks received: %d\n", ccblocks_in_avc_total); mprint ("Total caption blocks lost: %d\n", ccblocks_in_avc_lost); } mprint ("This is beta software. Report issues to carlos at ccextractor org...\n"); if (show_myth_banner) { mprint ("NOTICE: Due to the major rework in 0.49, we needed to change part of the timing\n"); mprint ("code in the MythTV's branch. Please report results to the address above. If\n"); mprint ("something is broken it will be fixed. Thanks\n"); } dinit_libraries(&ctx); return EXIT_OK; }
void main(void) { TRISA = 0x0; TRISB = 0x0; TRISC = 0x0; PORTA = 0x0; PORTB = 0x0; PORTC = 0x0; LATA = 0x0; LATB = 0x0; LATC = 0x0; signed char length; unsigned char msgtype; uart_comm uc; i2c_comm ic; unsigned char msgbuffer[MSGLEN + 1]; uart_thread_struct uthread_data; // info for uart_lthread timer0_thread_struct t0thread_data; timer1_thread_struct t1thread_data; // info for timer1_lthread encoder_struct encoder_data; sensor_data sensors; #ifdef __USE18F2680 OSCCON = 0xFC; // see datasheet // We have enough room below the Max Freq to enable the PLL for this chip OSCTUNEbits.PLLEN = 1; // 4x the clock speed in the previous line #else OSCCON = 0x82; // see datasheeet OSCTUNEbits.PLLEN = 0; // Makes the clock exceed the PIC's rated speed if the PLL is on #endif #ifdef SENSORPIC i2c2_comm ic2; init_i2c2(&ic2); #endif // initialize everything init_uart_comm(&uc); init_i2c(&ic); init_encoder(&encoder_data); init_timer0_lthread(&t0thread_data); init_timer1_lthread(&t1thread_data); init_uart_lthread(&uthread_data); init_queues(); #ifdef MASTERPIC // Enable and set I2C interrupt to high i2c_configure_master(); IPR1bits.SSPIP = 1; PIE1bits.SSPIE = 1; // initialize Timer0 to go off approximately every 10 ms //OpenTimer0(TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_1); CloseTimer0(); INTCONbits.TMR0IE = 0; //Enable Timer0 Interrupt // Configure UART OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 9); // 19.2kHz (197910/t - 1 = target) IPR1bits.RCIP = 0; IPR1bits.TXIP = 0; uc.expected = 1; PORTB = 0x0; LATB = 0x0; TRISB = 0x0; #endif //MASTERPIC #ifdef SENSORPIC // Enable and set I2C interrupt to high i2c_configure_slave(SENSORPICADDR); IPR1bits.SSPIP = 1; PIE1bits.SSPIE = 1; i2c2_configure_master(); IPR3bits.SSP2IP = 1; PIE3bits.SSP2IE = 1; // Open ADC on channel 1 ADCON0= 0x01; ADCON1=0x30; ADCON2=0xa1; TRISA=0x0F; PIE1bits.ADIE = 1; //Enabling ADC interrupts IPR1bits.ADIP = 0; //Setting A/D priority // initialize Timer0 to go off approximately every 10 ms OpenTimer0(TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_128); INTCONbits.TMR0IE = 1; //Enable Timer0 Interrupt INTCON2bits.TMR0IP = 0; //TMR0 set to Low Priority Interrupt #endif //SENSORPIC #ifdef MOTORPIC i2c_configure_slave(MOTORPICADDR); // Enable and set I2C interrupt to high IPR1bits.SSPIP = 1; PIE1bits.SSPIE = 1; // Configure UART OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 0x9); IPR1bits.RCIP = 0; IPR1bits.TXIP = 0; INTCONbits.TMR0IE = 0; // Disable Timer0 Interrupt PORTB = 0x0; LATB = 0x0; TRISB = 0x0; // Set up RB5 as interrupt TRISBbits.RB5 = 1; INTCON2bits.RBIP = 0; #endif //MOTORPIC #ifdef MASTERPIC //init_communication(MOTORPICADDR); //init_communication(SENSORPICADDR); #endif // Peripheral interrupts can have their priority set to high or low // enable high-priority interrupts and low-priority interrupts enable_interrupts(); while (1) { // Spins until a message appears block_on_To_msgqueues(); // Continuously check high priority messages until it is empty while((length = ToMainHigh_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer)) >= 0) { switch (msgtype) { case MSGT_I2C_RQST: { #ifdef SENSORPIC char command = msgbuffer[0]; char length = 0; char buffer[8]; switch(command) { case SHORT_IR1_REQ: { length = 2; buffer[0] = command; buffer[1] = 0x11; } break; case SHORT_IR2_REQ: { length = 2; buffer[0] = command; buffer[1] = 0x22; } break; case MID_IR1_REQ: { length = 2; buffer[0] = command; buffer[1] = 0x33; } break; case MID_IR2_REQ: { length = 2; buffer[0] = command; buffer[1] = 0x44; } break; case COMPASS_REQ: { length = 2; buffer[0] = command; buffer[1] = 0x55; } break; case ULTRASONIC_REQ: { length = 2; buffer[0] = command; buffer[1] = 0x66; } break; default: { length = 2; buffer[0] = 0x0; buffer[1] = 0x0; } break; } if(length > 0) { start_i2c_slave_reply(length,buffer); } #endif #ifdef MOTORPIC unsigned char buffer[8]; unsigned char length = 0; char command = msgbuffer[0]; buffer[0] = command; switch(command) { case MOVE_FORWARD_CMD: { length = 1; motor_move_forward(10); INTCONbits.RBIE = 1; // Temporary } break; case MOVE_BACKWARD_CMD: { length = 1; motor_move_backward(10); } break; case TURN_RIGHT_CMD: { length = 1; motor_turn_right(10); } break; case TURN_LEFT_CMD: { length = 1; motor_turn_left(10); } break; case STOP_CMD: { length = 1; motor_stop(); } break; case DISTANCE_REQ: { INTCONbits.RBIE = 0; // Temporary buffer[1] = encoder_to_distance(); length = 2; } break; default: { buffer[0] = 0x0; length = 1; } break; } if(length > 0) { start_i2c_slave_reply(length,buffer); } #endif } break; case MSGT_I2C_DATA: { } break; case MSGT_I2C_MASTER_SEND_COMPLETE: { #ifdef MASTERPIC /* char command = msgbuffer[0]; switch(command) { case MOVE_FORWARD_CMD: case MOVE_BACKWARD_CMD: case TURN_RIGHT_CMD: case TURN_LEFT_CMD: case STOP_CMD: { i2c_master_recv(1,MOTORPICADDR); } break; case DISTANCE_REQ: { i2c_master_recv(2,MOTORPICADDR); } break; case SHORT_IR1_REQ: case SHORT_IR2_REQ: case MID_IR1_REQ: case MID_IR2_REQ: case COMPASS_REQ: case ULTRASONIC_REQ: { i2c_master_recv(2,SENSORPICADDR); } break; default: { } break; }*/ #endif #ifdef SENSORPIC // Start receiving data from sensor if(t0thread_data.currentState == readCompassState) { i2c2_master_recv(6,COMPASSADDR); } else if(t0thread_data.currentState == readUltrasonicState) { i2c2_master_recv(2,ULTRASONICADDR); } #endif } break; case MSGT_I2C_MASTER_SEND_FAILED: { } break; case MSGT_I2C_MASTER_RECV_COMPLETE: { #ifdef MASTERPIC char buffer[2]; char length = 0; char command = msgbuffer[0]; switch(command) { case MOVE_FORWARD_CMD: case MOVE_BACKWARD_CMD: case TURN_RIGHT_CMD: case TURN_LEFT_CMD: case STOP_CMD: { buffer[0] = command; length = 1; } break; case DISTANCE_REQ: { buffer[0] = command; buffer[1] = msgbuffer[1]; length = 2; } break; case SHORT_IR1_REQ: case SHORT_IR2_REQ: case MID_IR1_REQ: case MID_IR2_REQ: case COMPASS_REQ: case ULTRASONIC_REQ: { buffer[0] = command; buffer[1] = msgbuffer[1]; length = 2; } break; default: { length = 0; } break; } if(length > 0) { start_uart_send(length,buffer); } #endif #ifdef SENSORPIC // Received data from sensor if(t0thread_data.currentState == readCompassState) { sensors.compassData[0] = msgbuffer[0]; sensors.compassData[1] = msgbuffer[1]; sensors.compassData[2] = msgbuffer[2]; sensors.compassData[3] = msgbuffer[3]; sensors.compassData[4] = msgbuffer[4]; sensors.compassData[5] = msgbuffer[5]; } else if(t0thread_data.currentState == readUltrasonicState) { } #endif } break; case MSGT_I2C_MASTER_RECV_FAILED: { } break; case MSGT_I2C_DBG: { } break; default: { } break; } } // Error check if (length != MSGQUEUE_EMPTY) { // Handle Error } // Check the low priority queue if ((length = ToMainLow_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer)) >= 0) { switch (msgtype) { case MSGT_TIMER0: { timer0_lthread(&t0thread_data, msgtype, length, msgbuffer); } break; case MSGT_TIMER1: timer1_lthread(&t1thread_data, msgtype, length, msgbuffer); break; case ADCSC1_ADCH: ADC_lthread(&ADCthread_data, msgtype, length, msgbuffer,&t0thread_data); break; case MSGT_OVERRUN: case MSGT_UART_DATA: { uart_lthread(&uthread_data, msgtype, length, msgbuffer); } break; case MSGT_UART_SEND_COMPLETE: { } break; default: break; } } // Error check else if (length != MSGQUEUE_EMPTY) { // Handle error } } }
static switch_status_t switch_dahdi_encode(switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data, uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag) { int32_t res; short *dbuf_linear; unsigned char *ebuf_g729; unsigned char ebuf_ulaw[decoded_data_len / 2]; uint32_t i; struct dahdi_context *context = NULL; switch_status_t status; #ifdef DEBUG_DAHDI_CODEC switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Switch DAHDI encode called to encode %d bytes.\n", decoded_data_len); #endif context = codec->private_info; if (context->encoding_fd == -1) { if ((status = init_encoder(codec)) != SWITCH_STATUS_SUCCESS) { return status; } } dbuf_linear = decoded_data; ebuf_g729 = encoded_data; for (i = 0; i < decoded_data_len / sizeof(short); i++) { ebuf_ulaw[i] = linear_to_ulaw(dbuf_linear[i]); } #ifdef DEBUG_DAHDI_CODEC switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Writing %d bytes of decoded ulaw data.\n", i); #endif res = write(context->encoding_fd, ebuf_ulaw, i); if (-1 == res) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to write to %s encoder device.\n", transcoder_name); return SWITCH_STATUS_FALSE; } if (i != res) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested to write %d bytes to %s encoder device, but only wrote %d bytes.\n", i, transcoder_name, res); return SWITCH_STATUS_FALSE; } res = wait_for_transcoder(context->encoding_fd); if (-1 == res) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to poll on %s encoder device: %s.\n", transcoder_name, strerror(errno)); return SWITCH_STATUS_FALSE; } if (0 == res) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No output on %s encoder device.\n", transcoder_name); *encoded_data_len = 0; return SWITCH_STATUS_SUCCESS; } #ifdef DEBUG_DAHDI_CODEC switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attempting to read %d bytes of encoded data.\n", *encoded_data_len); #endif res = read(context->encoding_fd, encoded_data, *encoded_data_len); if (-1 == res) { if (EAGAIN == errno || EWOULDBLOCK == errno) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No output on %s encoder device (%s).\n", transcoder_name, strerror(errno)); *encoded_data_len = 0; return SWITCH_STATUS_SUCCESS; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to read from %s encoder device: %s.\n", transcoder_name, strerror(errno)); return SWITCH_STATUS_FALSE; } *encoded_data_len = res; #ifdef DEBUG_DAHDI_CODEC switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Read %d bytes of encoded data.\n", res); #endif return SWITCH_STATUS_SUCCESS; }
static int alloc(struct vidcodec_st **stp, struct vidcodec *vc, const char *name, struct vidcodec_prm *encp, const char *fmtp, vidcodec_enq_h *enqh, vidcodec_send_h *sendh, void *arg) { struct vidcodec_st *st; int err = 0; if (!encp) return EINVAL; st = mem_zalloc(sizeof(*st), destructor); if (!st) return ENOMEM; st->vc = mem_ref(vc); st->encprm = *encp; if (0 == str_casecmp(name, "H263")) st->codec_id = CODEC_ID_H263; else if (0 == str_casecmp(name, "H264")) st->codec_id = CODEC_ID_H264; else if (0 == str_casecmp(name, "MP4V-ES")) st->codec_id = CODEC_ID_MPEG4; else { err = EINVAL; goto out; } st->enc.mb = mbuf_alloc(FF_MIN_BUFFER_SIZE * 20); st->dec.mb = mbuf_alloc(1024); st->mb_frag = mbuf_alloc(1024); if (!st->enc.mb || !st->dec.mb || !st->mb_frag) { err = ENOMEM; goto out; } st->enc.sz_max = st->enc.mb->size; st->dec.sz_max = st->dec.mb->size; if (st->codec_id == CODEC_ID_H264) { #ifndef USE_X264 err = init_encoder(st); #endif } else err = init_encoder(st); if (err) { DEBUG_WARNING("%s: could not init encoder\n", name); goto out; } err = init_decoder(st); if (err) { DEBUG_WARNING("%s: could not init decoder\n", name); goto out; } if (str_isset(fmtp)) { struct pl sdp_fmtp; pl_set_str(&sdp_fmtp, fmtp); fmt_param_apply(&sdp_fmtp, param_handler, st); } st->enqh = enqh; st->sendh = sendh; st->arg = arg; re_printf("video codec %s: %d fps, %d bit/s\n", name, encp->fps, encp->bitrate); out: if (err) mem_deref(st); else *stp = st; return err; }
void setup(){ init_ros(); init_imu(); init_controller(); init_encoder(); }
struct encoder_ctx *update_encoder_list_cinfo(struct lib_ccx_ctx *ctx, struct cap_info* cinfo) { struct encoder_ctx *enc_ctx; unsigned int pn = 0; unsigned char in_format = 1; char *extension; if (ctx->write_format == CCX_OF_NULL) return NULL; if(cinfo) { pn = cinfo->program_number; if (cinfo->codec == CCX_CODEC_ISDB_CC) in_format = 3; else if (cinfo->codec == CCX_CODEC_TELETEXT) in_format = 2; else in_format = 1; } list_for_each_entry(enc_ctx, &ctx->enc_ctx_head, list, struct encoder_ctx) { if ( ctx->multiprogram == CCX_FALSE) return enc_ctx; if (enc_ctx->program_number == pn) return enc_ctx; } extension = get_file_extension(ccx_options.enc_cfg.write_format); if (!extension && ccx_options.enc_cfg.write_format != CCX_OF_CURL) return NULL; if(ctx->multiprogram == CCX_FALSE) { if(ctx->out_interval != -1) { int len; len = strlen(ctx->basefilename) + 10 + strlen(extension); freep(&ccx_options.enc_cfg.output_filename); ccx_options.enc_cfg.output_filename = malloc(len); sprintf(ccx_options.enc_cfg.output_filename, "%s_%06d%s", ctx->basefilename, ctx->segment_counter+1, extension); } if (list_empty(&ctx->enc_ctx_head)) { ccx_options.enc_cfg.program_number = pn; ccx_options.enc_cfg.in_format = in_format; enc_ctx = init_encoder(&ccx_options.enc_cfg); if (!enc_ctx) return NULL; list_add_tail( &(enc_ctx->list), &(ctx->enc_ctx_head) ); } } else { int len; len = strlen(ctx->basefilename) + 10 + strlen(extension); ccx_options.enc_cfg.program_number = pn; ccx_options.enc_cfg.output_filename = malloc(len); if (!ccx_options.enc_cfg.output_filename) { freep(&extension); return NULL; } sprintf(ccx_options.enc_cfg.output_filename, "%s_%d%s", ctx->basefilename, pn, extension); enc_ctx = init_encoder(&ccx_options.enc_cfg); if (!enc_ctx) { freep(&extension); freep(&ccx_options.enc_cfg.output_filename); return NULL; } list_add_tail( &(enc_ctx->list), &(ctx->enc_ctx_head) ); freep(&extension); freep(&ccx_options.enc_cfg.output_filename); } // DVB related enc_ctx->prev = NULL; if (cinfo) if (cinfo->codec == CCX_CODEC_DVB) enc_ctx->write_previous = 0; freep(&extension); return enc_ctx; }
video_encoder_t* init_video_encoder(InputParams_videoencoder *pInputParams) { if(pInputParams == NULL) { fprintf(stderr ,"libvideoencoder: Error paraments..\n"); return NULL; } videoencoder_instanse *p_instanse = (videoencoder_instanse *)malloc(sizeof(videoencoder_instanse)); if(p_instanse == NULL) { fprintf(stderr ,"libvideoencoder: Error malloc..\n"); return NULL; } p_instanse->width = pInputParams->width; p_instanse->height = pInputParams->height; p_instanse->gopsize_min = pInputParams->gopsize_min; p_instanse->gopsize_max = pInputParams->gopsize_max; p_instanse->fps = pInputParams->fps; p_instanse->bitrate = pInputParams->bitrate/1024; p_instanse->real_count_fps = 0; p_instanse->outbf = (unsigned char *)malloc(p_instanse->width*p_instanse->height*2); p_instanse->enc_buf = (unsigned char *)malloc(p_instanse->width*p_instanse->height*2); p_instanse->rgb_buffer = (unsigned char *)malloc(p_instanse->width*p_instanse->height*4); if(p_instanse->outbf == NULL || p_instanse->enc_buf == NULL || p_instanse->rgb_buffer == NULL) { fprintf(stderr ,"libvideoencoder: Error malloc..\n"); return NULL; } unsigned char parn=0; char mkarg[30][30]; char * parg[30]; sprintf(mkarg[parn],"main\0"); parg[parn]=mkarg[parn]; parn++; sprintf(mkarg[parn],"%d\0",p_instanse->width); parg[parn]=mkarg[parn]; parn++; sprintf(mkarg[parn],"%d\0",p_instanse->height); parg[parn]=mkarg[parn]; parn++; if(p_instanse->width<=720) p_instanse->bitrate=4000; else if(p_instanse->width<=1280 && p_instanse->width>720 ) p_instanse->bitrate=4000; else if(p_instanse->width>1280) p_instanse->bitrate=9000; sprintf(mkarg[parn],"fb=%d\0",p_instanse->bitrate); parg[parn]=mkarg[parn]; parn++; sprintf(mkarg[parn],"mode=%d\0",1); parg[parn]=mkarg[parn]; parn++; //fprintf(stderr ,"libvideoencoder: Init H.264 encoder..\n"); if(init_encoder(parn,parg) != 0) { fprintf(stderr ,"libvideoencoder: Init H.264 encoder error..\n"); return NULL; } //fprintf(stderr ,"libvideoencoder: Init H.264 encoder success with w=%d,h=%d\n",p_instanse->width,p_instanse->height); return p_instanse; }
int main(int argc, char **argv) { int stop_at = 0; char *yuv_path; if (argc == 2) { yuv_path = argv[1]; } else if (argc == 3) { yuv_path = argv[1]; stop_at = atoi(argv[2]); } else { printf("usage: %s input [max frames]\n", argv[0]); return -1; } printf("[test] initializing streams list\n"); printf("[test] init_stream_list\n"); stream_list_t *streams = init_stream_list(); printf("[test] init_stream\n"); stream_data_t *stream = init_stream(VIDEO, OUTPUT, 0, ACTIVE, "i2catrocks"); printf("[test] set_stream_video_data\n"); printf("[test] add_stream\n"); add_stream(streams, stream); printf("[test] initializing transmitter\n"); transmitter_t *transmitter = init_transmitter(streams, 20.0); start_transmitter(transmitter); rtsp_serv_t *server; server = malloc(sizeof(rtsp_serv_t)); server->port = 8554; server->streams = streams; server->transmitter = transmitter; init_encoder(stream->video); c_start_server(server); c_update_server(server); // Stuff ... AVFormatContext *pformat_ctx = avformat_alloc_context(); AVCodecContext codec_ctx; int video_stream = -1; av_register_all(); int width = 1280; int height = 534; load_video(yuv_path, pformat_ctx, &codec_ctx, &video_stream); uint8_t *b1 = (uint8_t *)av_malloc(avpicture_get_size(codec_ctx.pix_fmt, codec_ctx.width, codec_ctx.height)*sizeof(uint8_t)); int counter = 0; struct timeval a, b; video_data_frame_t *decoded_frame; while(1) { gettimeofday(&a, NULL); int ret = read_frame(pformat_ctx, video_stream, &codec_ctx, b1); if (stop_at > 0 && counter == stop_at) { break; } if (ret == 0) { counter++; decoded_frame = curr_in_frame(stream->video->decoded_frames); if (decoded_frame == NULL){ continue; } decoded_frame->buffer_len = vc_get_linesize(width, RGB)*height; memcpy(decoded_frame->buffer, b1, decoded_frame->buffer_len); put_frame(stream->video->decoded_frames); } else { break; } gettimeofday(&b, NULL); long diff = (b.tv_sec - a.tv_sec)*1000000 + b.tv_usec - a.tv_usec; if (diff < 40000) { usleep(40000 - diff); } else { usleep(0); } } debug_msg(" deallocating resources and terminating threads\n"); av_free(pformat_ctx); av_free(b1); debug_msg(" done!\n"); stop_transmitter(transmitter); destroy_stream_list(streams); return 0; }
int encode_update(struct videnc_state **vesp, const struct vidcodec *vc, struct videnc_param *prm, const char *fmtp, videnc_packet_h *pkth, void *arg) { struct videnc_state *st; int err = 0; if (!vesp || !vc || !prm || !pkth) return EINVAL; if (*vesp) return 0; st = mem_zalloc(sizeof(*st), destructor); if (!st) return ENOMEM; st->encprm = *prm; st->pkth = pkth; st->arg = arg; st->codec_id = avcodec_resolve_codecid(vc->name); if (st->codec_id == AV_CODEC_ID_NONE) { err = EINVAL; goto out; } st->mb = mbuf_alloc(FF_MIN_BUFFER_SIZE * 20); st->mb_frag = mbuf_alloc(1024); if (!st->mb || !st->mb_frag) { err = ENOMEM; goto out; } st->sz_max = st->mb->size; if (st->codec_id == AV_CODEC_ID_H264) { #ifndef USE_X264 err = init_encoder(st); #endif } else err = init_encoder(st); if (err) { warning("avcodec: %s: could not init encoder\n", vc->name); goto out; } if (str_isset(fmtp)) { struct pl sdp_fmtp; pl_set_str(&sdp_fmtp, fmtp); fmt_param_apply(&sdp_fmtp, param_handler, st); } debug("avcodec: video encoder %s: %d fps, %d bit/s, pktsize=%u\n", vc->name, prm->fps, prm->bitrate, prm->pktsize); out: if (err) mem_deref(st); else *vesp = st; return err; }
EXPORT void *init_capture(const char *in, const char *out, struct inputCfg *cfg) { int ret = 0; // structure with ffmpeg variables struct liveStream *ctx = NULL; AVStream *stream = NULL; // allocation of Live Stream structure ctx = malloc(sizeof(struct liveStream)); if(ctx == NULL) { fprintf(stderr,"Error in liveStream struct alloc\n"); return NULL; } memset(ctx, 0, sizeof(*ctx)); init_ffmpeg(); ret = configure_input(ctx, in, cfg); if(ret < 0) { av_log(NULL,AV_LOG_ERROR,"unable to configure input\n"); free(ctx); return NULL; } stream = ctx->inputs[0].st; /** Initalize framerate coming from webcam */ if(stream->avg_frame_rate.num && stream->avg_frame_rate.den) { ctx->video_avg_frame_rate.num = stream->avg_frame_rate.num; ctx->video_avg_frame_rate.den = stream->avg_frame_rate.den; } else if(stream->r_frame_rate.num && stream->r_frame_rate.den ) { ctx->video_avg_frame_rate.num = stream->r_frame_rate.num; ctx->video_avg_frame_rate.den = stream->r_frame_rate.den; } else { fprintf(stderr, "Unable to take out fps from webcam assuming 30fps\n"); ctx->video_avg_frame_rate.num = 30; ctx->video_avg_frame_rate.den = 1; } ctx->have_filter = 1; ret = init_filters(ctx); if(ret < 0) { fprintf(stderr,"unable to initialize filter\n"); goto end; } ret = init_encoder(ctx, out); if(ret < 0) { printf("Error in encoder init for %s\n", out); ret =-1; goto end; } ctx->OutFrame = av_frame_alloc(); end: if(ret < 0) { stop_capture((void*)ctx); return NULL; } return ctx; }
int hardsubx_process_data(struct lib_hardsubx_ctx *ctx) { // Get the required media attributes and initialize structures av_register_all(); if(avformat_open_input(&ctx->format_ctx, ctx->inputfile[0], NULL, NULL)!=0) { fatal (EXIT_READ_ERROR, "Error reading input file!\n"); } if(avformat_find_stream_info(ctx->format_ctx, NULL)<0) { fatal (EXIT_READ_ERROR, "Error reading input stream!\n"); } // Important call in order to determine media information using ffmpeg // TODO: Handle multiple inputs av_dump_format(ctx->format_ctx, 0, ctx->inputfile[0], 0); ctx->video_stream_id = -1; for(int i = 0; i < ctx->format_ctx->nb_streams; i++) { if(ctx->format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { ctx->video_stream_id = i; break; } } if(ctx->video_stream_id == -1) { fatal (EXIT_READ_ERROR, "Video Stream not found!\n"); } ctx->codec_ctx = ctx->format_ctx->streams[ctx->video_stream_id]->codec; ctx->codec = avcodec_find_decoder(ctx->codec_ctx->codec_id); if(ctx->codec == NULL) { fatal (EXIT_READ_ERROR, "Input codec is not supported!\n"); } if(avcodec_open2(ctx->codec_ctx, ctx->codec, &ctx->options_dict) < 0) { fatal (EXIT_READ_ERROR, "Error opening input codec!\n"); } ctx->frame = av_frame_alloc(); ctx->rgb_frame = av_frame_alloc(); if(!ctx->frame || !ctx->rgb_frame) { fatal(EXIT_NOT_ENOUGH_MEMORY, "Not enough memory to initialize frame!"); } int frame_bytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, ctx->codec_ctx->width, ctx->codec_ctx->height, 16); ctx->rgb_buffer = (uint8_t *)av_malloc(frame_bytes*sizeof(uint8_t)); ctx->sws_ctx = sws_getContext( ctx->codec_ctx->width, ctx->codec_ctx->height, ctx->codec_ctx->pix_fmt, ctx->codec_ctx->width, ctx->codec_ctx->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL,NULL,NULL ); av_image_fill_arrays(ctx->rgb_frame->data, ctx->rgb_frame->linesize, ctx->rgb_buffer, AV_PIX_FMT_RGB24, ctx->codec_ctx->width, ctx->codec_ctx->height, 1); // int frame_bytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, 1280, 720, 16); // ctx->rgb_buffer = (uint8_t *)av_malloc(frame_bytes*sizeof(uint8_t)); // ctx->sws_ctx = sws_getContext( // ctx->codec_ctx->width, // ctx->codec_ctx->height, // ctx->codec_ctx->pix_fmt, // 1280, // 720, // AV_PIX_FMT_RGB24, // SWS_BILINEAR, // NULL,NULL,NULL // ); // avpicture_fill((AVPicture*)ctx->rgb_frame, ctx->rgb_buffer, AV_PIX_FMT_RGB24, 1280, 720); // av_image_fill_arrays(ctx->rgb_frame->data, ctx->rgb_frame->linesize, ctx->rgb_buffer, AV_PIX_FMT_RGB24, 1280, 720, 1); // Pass on the processing context to the appropriate functions struct encoder_ctx *enc_ctx; enc_ctx = init_encoder(&ccx_options.enc_cfg); mprint("Beginning burned-in subtitle detection...\n"); hardsubx_process_frames_linear(ctx, enc_ctx); dinit_encoder(&enc_ctx, 0); //TODO: Replace 0 with end timestamp // Free the allocated memory for frame processing av_free(ctx->rgb_buffer); av_free(ctx->rgb_frame); av_free(ctx->frame); avcodec_close(ctx->codec_ctx); avformat_close_input(&ctx->format_ctx); }