/** * \brief Reads a 'concord.ind' file and returns a fifo list of all matches found and their replacement * * \param[in] concord_file_name the name of the concord.ind file * * \return a fifo list of all the matches found with their replacement sentences. Each element is * stored in a locate_pos structure */ struct fifo *read_concord_file(const char *concord_file_name,int mask_encoding_compatibility_input){ unichar line[4096]; struct fifo *f = new_fifo(); U_FILE *concord_desc_file; concord_desc_file = u_fopen_existing_versatile_encoding(mask_encoding_compatibility_input, concord_file_name,U_READ); if( concord_desc_file == NULL){ perror("u_fopen\n"); fprintf(stderr,"Cannot open file %s\n",concord_file_name); exit(1); } if(u_fgets(line,4096,concord_desc_file)==EOF){ fatal_error("Malformed concordance file %s",concord_file_name); } while(u_fgets(line,4096,concord_desc_file)!=EOF){ // we don't want the end of line char line[u_strlen(line)-1]='\0'; locate_pos *l = read_concord_line(line); put_ptr(f,l); } u_fclose(concord_desc_file); return f; }
struct fifo *load_transducer_from_linked_list(const struct transducer_name_and_mode_linked_list *list,const char* transducer_filename_prefix){ struct fifo *transducer_fifo = new_fifo(); int i=1; while (list != NULL){ char *transducer_file_name; OutputPolicy transducer_policy; transducer *t; transducer_file_name = list->transducer_filename; //fprintf(stdout, "transducer name read =%s\n",transducer_file_name); transducer_policy = list->transducer_mode; if (transducer_file_name != NULL && transducer_policy != IGNORE_OUTPUTS) { //fprintf(stdout,"transducer to be loaded\n"); t = (transducer*) malloc(sizeof(transducer) * 1); if (t == NULL) { perror("malloc\n"); fprintf(stderr, "Impossible to allocate memory\n"); exit(1); } size_t transducer_filename_prefix_len = 0; if (transducer_filename_prefix != NULL) transducer_filename_prefix_len = strlen(transducer_filename_prefix); t->transducer_file_name = (char*)malloc(sizeof(char)*(transducer_filename_prefix_len+strlen(transducer_file_name)+1)); if(t->transducer_file_name == NULL){ perror("malloc\n"); fprintf(stderr,"Impossible to allocate memory\n"); exit(1); } t->transducer_file_name[0] = '\0'; if (transducer_filename_prefix != NULL) strcpy(t->transducer_file_name, transducer_filename_prefix); strcat(t->transducer_file_name, transducer_file_name); t->output_policy = transducer_policy; struct any value; value._ptr = t; put_any(transducer_fifo,value); if (!is_empty(transducer_fifo)) { fprintf(stdout, "transducer %s successfully loaded\n", t->transducer_file_name); } } else { if (transducer_file_name == NULL) { fprintf(stdout, "Transducer %d : Empty filename\n",i); } else if (transducer_policy == IGNORE_OUTPUTS) { fprintf(stdout, "Transducer %d : Transducer mode not recognized\n",i); } } i++; list=list->next; } return transducer_fifo; }
bool VideoLayer::open(const char *file) { AVCodecContext *enc; // tmp int err=0; video_index=-1; func("VideoLayer::open(%s)",file); AVInputFormat *av_input_format = NULL; AVFormatParameters avp, *av_format_par = NULL; av_format_par = &avp; memset (av_format_par, 0, sizeof (*av_format_par)); av_format_par->width=0; av_format_par->width=0; av_format_par->time_base = (AVRational){1, 25}; av_format_par->pix_fmt=PIX_FMT_RGB32; /* handle firewire cam */ if( strncasecmp (file, "/dev/ieee1394/",14) == 0) { notice ("VideoLayer::found dv1394 device!\n"); grab_dv = true; av_input_format = av_find_input_format("dv1394"); /** shit XXX */ av_format_par -> width = 720; av_format_par -> height = 576; #if LIBAVCODEC_BUILD >= 4754 av_format_par -> time_base.num = 25; av_format_par -> time_base.den = 1; #else av_format_par -> frame_rate = 25; av_format_par -> frame_rate_base = 1; #endif // field removed in recent ffmpeg API (todo: check LIBAVCODEC_BUILD) // av_format_par -> device = file; av_format_par -> standard = "pal"; // av_format_par->channel=0; file=""; } /** * The callback is called in blocking functions to test regulary if * asynchronous interruption is needed. -EINTR is returned in this * case by the interrupted function. 'NULL' means no interrupt * callback is given. */ url_set_interrupt_cb(NULL); /** * Open media with libavformat */ err = av_open_input_file (&avformat_context, file, av_input_format, 0, av_format_par); if (err < 0) { error("VideoLayer :: open(%s) - can't open. Error %d", file, err); return false; } func("VideoLayer :: file opened with success"); /** * Find info with libavformat */ err = av_find_stream_info(avformat_context); if (err < 0) { error("VideoLayer :: could not find stream info"); return false; } func("VideoLayer :: stream info found"); /* now we can begin to play (RTSP stream only) */ av_read_play(avformat_context); /** * Open codec if we find a video stream */ unsigned int i; for(i=0; i < avformat_context -> nb_streams; i++) { avformat_stream = avformat_context -> streams[i]; enc = avformat_stream->codec; if(enc == NULL) error("%s: AVCodecContext is NULL", __PRETTY_FUNCTION__); switch(enc->codec_type) { /** * Here we look for a video stream */ // case CODEC_TYPE_VIDEO: // old FFMPEG case AVMEDIA_TYPE_VIDEO: // enc->flags |= CODEC_FLAG_LOOP_FILTER; video_index = i; video_codec_ctx = enc; video_codec = avcodec_find_decoder (video_codec_ctx -> codec_id); if(video_codec==NULL) { error("VideoLayer :: Could not find a suitable codec"); return false; } if (avcodec_open(video_codec_ctx, video_codec) < 0) { error("VideoLayer :: Could not open codec"); return false; } else { // correctly opened #if LIBAVCODEC_BUILD >= 4754 if(avformat_stream->r_frame_rate.den && avformat_stream->r_frame_rate.num) frame_rate = av_q2d(avformat_stream->r_frame_rate); else frame_rate = enc -> time_base.den / enc -> time_base.num; AVRational rational = enc -> time_base; func ("VideoLayer :: frame_rate den: %d", enc -> time_base .den); func ("VideoLayer :: frame_rate num: %d", enc -> time_base .num); #else frame_rate = video_codec_ctx->frame_rate / video_codec_ctx->frame_rate_base; #endif // set the layer fps fps.set(frame_rate); /* this saves only file without full path! */ set_filename (file); act ("%s (codec: %s) has resolution %dx%d and framerate %f", get_filename(), video_codec->name, video_codec_ctx->width, video_codec_ctx->height, frame_rate); break; } break; // //////////////// end of video section case AVMEDIA_TYPE_AUDIO: audio_index = i; audio_codec_ctx = enc; func ("VideoLayer :: audio id=%i", audio_index); audio_codec = avcodec_find_decoder(audio_codec_ctx -> codec_id); if(audio_codec==NULL) { error("VideoLayer :: Could not find a suitable codec for audio"); return false; } if (avcodec_open(audio_codec_ctx, audio_codec) < 0) { error("VideoLayer :: Could not open codec for audio"); return false; } else { // correctly opened //AVCODEC_MAX_AUDIO_FRAME_SIZE = 192000 audio_buf = (uint8_t*)calloc(AVCODEC_MAX_AUDIO_FRAME_SIZE, sizeof(int16_t)); audio_channels = audio_codec_ctx->channels; audio_samplerate = audio_codec_ctx->sample_rate; audio_float_buf = (float*) malloc(audio_channels * AVCODEC_MAX_AUDIO_FRAME_SIZE * sizeof(float)); act("VideoLayer :: audio stream (codec: %s) has %u channels at samplerate %u", audio_codec->name, audio_channels, audio_samplerate); } break; // /////// end of audio section case AVMEDIA_TYPE_SUBTITLE: act("stream has also subtitles"); break; case AVMEDIA_TYPE_ATTACHMENT: act("stream has also attachment"); break; case AVMEDIA_TYPE_DATA: act("stream has also a data carrier"); break; default: act("stream has also an unknown codec stream"); break; } } // done looking for streams if (video_index < 0) { error("VideoLayer :: Could not open codec"); return false; } full_filename = strdup (file); geo.init(video_codec_ctx->width, video_codec_ctx->height, 32); func("VideoLayer :: w[%u] h[%u] size[%u]", geo.w, geo.h, geo.bytesize); func("VideoLayer :: frame_rate[%f]",frame_rate); // initialize picture if( new_picture(rgba_picture) < 0) { error("VideoLayer::error allocating picture"); return false; } #ifdef WITH_SWSCALE img_convert_ctx = sws_getContext(geo.w, geo.h, video_codec_ctx->pix_fmt, geo.w, geo.h, PIX_FMT_RGB32, SWS_BICUBIC, NULL, NULL, NULL); #endif // initialize frame fifo if( new_fifo() < 0) { error("VideoLayer::error allocating fifo"); return false; } // feed() function is called 25 times for second so we must correct the speed // TODO user should be able to select the clock speed if (play_speed != 25) { play_speed -= (25 / frame_rate); // play_speed -= play_speed << 1; if ( frame_rate ==1) play_speed = 0; } func ("VideoLayer :: play_speed: %d",play_speed); opened = true; type = VIDEOLAYER; return true; }