예제 #1
0
int main()
{
    int context;
    int i,j,k=OF_CODEC_LDPC_STAIRCASE_STABLE;
    of_session_t *ses;
    of_status_t ret;
    // LDPC parameters
      of_ldpc_parameters_t		params;
      params.nb_source_symbols		= 1000;
      params.nb_repair_symbols		= 500;
      params.encoding_symbol_length	= 1024;
      params.prng_seed			= rand();
      params.N1				= 5;


    char **orig_symb_tab;
    void **encoding_symb_tab;
    //for (k=0;k<CODEC_MAX;k++)
    {
	// create an instance of an encoder
      if ((ret = of_create_codec_instance(&ses,k,OF_ENCODER,1)) != OF_STATUS_OK)
      {
	printf("error in of_create_codec_instance\n");
	goto error;      
      }

      if (of_set_fec_parameters(ses, (of_parameters_t*)&params) != OF_STATUS_OK) {
	      printf("error in of_set_fec_parameters\n");
	     goto error;
      }
      if( of_set_callback_functions(ses,source_cb,repair_cb,&context) != OF_STATUS_OK) {
	  printf ("error in of_set_fec_parameters\n");
      }
      
      orig_symb_tab = (char**)calloc(params.nb_source_symbols,sizeof(char*));
      encoding_symb_tab = (void*)calloc(params.nb_source_symbols+params.nb_repair_symbols,sizeof(void*));
      for(i=0;i<params.nb_source_symbols;i++)
      {
	  orig_symb_tab[i] = (char*)calloc(1,params.encoding_symbol_length);
	  encoding_symb_tab[i] = (void*)orig_symb_tab[i];
	  for (j=0;j<params.encoding_symbol_length;j++)
	  {
		orig_symb_tab[i][j] = rand();
	  }
      }
      
      for(i=params.nb_source_symbols;i<params.nb_source_symbols+params.nb_repair_symbols;i++)
      {
	  encoding_symb_tab[i] = (void*)calloc(1,params.encoding_symbol_length);
	  if (of_build_repair_symbol(ses,encoding_symb_tab,i) != OF_STATUS_OK)
	  {
	      printf("of_build_repair_symbol: ");;
	      //goto error;
	  }
      }
       if ((ret = of_release_codec_instance(ses)) != OF_STATUS_OK)
      {
	printf("of_release_codec_instance: ");;
	//goto error;
      }

	//create a decoder instance
      if ((ret = of_create_codec_instance(&ses,k,OF_DECODER,1)) != OF_STATUS_OK)
      {
	printf("of_create_codec_instance: ");
	;
	//goto error;
      }

      if (of_set_fec_parameters(ses, (of_parameters_t*)&params) != OF_STATUS_OK) {
	      printf(("of_set_fec_parameters(): "));;
	     // goto error;
      }
      if( of_set_callback_functions(ses,source_cb,repair_cb,&context) != OF_STATUS_OK) {
	  printf (("of_set_fec_parameters(): "));;
      }     
      for (i=380;i<1400;i++) //take 1020 symbols
      {
		  of_decode_with_new_symbol(ses,encoding_symb_tab[i],i);
      }

      of_finish_decoding(ses);
      printf("fini\n");

      if ((ret = of_release_codec_instance(ses)) != OF_STATUS_OK)
      {
	printf("of_release_codec_instance: ");;
	//goto error;
      }      
      free(encoding_symb_tab);
      free(orig_symb_tab);
    }
    printf ("nb : %i,%i\n",nb_source,nb_repair);
    printf("OK\n");
    return 0;
    
error:
  printf("error\n");
  return -1;
}
예제 #2
0
파일: fecdec.c 프로젝트: dasty/gstrtpfec
static void fec_dec_recover_packets(fec_dec *dec)
{
    of_session_t *session;
    of_rs_parameters_t params;
    void **encoding_symbol_tab;
    guint i;
    GList *link;

    assert(dec->has_snbase);
    assert(dec->max_packet_size > 0);

    encoding_symbol_tab = malloc(sizeof(void*) * (dec->num_media_packets + dec->num_fec_packets));
    memset(encoding_symbol_tab, 0, sizeof(void*) * (dec->num_media_packets + dec->num_fec_packets));

    for (link = g_queue_peek_head_link(dec->media_packets); link != NULL; link = link->next)
    {
        GstBuffer *media_packet;
        guint32 seqnum;

        media_packet = link->data;
        seqnum = fec_dec_correct_seqnum(dec, gst_rtp_buffer_get_seq(media_packet));

        encoding_symbol_tab[seqnum - dec->cur_snbase] = GST_BUFFER_DATA(media_packet);
    }

    for (link = g_queue_peek_head_link(dec->fec_packets); link != NULL; link = link->next)
    {
        GstBuffer *packet;
        guint8 *fec_data;
        guint8 esi;

        packet = link->data;
        fec_data = GST_BUFFER_DATA(packet) + gst_rtp_buffer_get_header_len(packet);
        esi = fec_data[12];

        encoding_symbol_tab[esi + dec->num_media_packets] = fec_data + RTP_FEC_HEADER_SIZE + 1;
    }

    params.nb_source_symbols = dec->num_media_packets;
    params.nb_repair_symbols = dec->num_fec_packets;
    params.encoding_symbol_length = dec->max_packet_size;

    of_create_codec_instance(&session, OF_CODEC_REED_SOLOMON_GF_2_8_STABLE, OF_DECODER, 0);
    of_set_fec_parameters(session, (of_parameters_t*)(&params));
    of_set_callback_functions(session, fec_dec_source_packet_cb, NULL, dec);

#if 1
    for (i = 0; i < dec->num_media_packets + dec->num_fec_packets; ++i)
    {
        if (encoding_symbol_tab[i] != 0)
            of_decode_with_new_symbol(session, encoding_symbol_tab[i], i);
    }
#else
    of_set_available_symbols(session, encoding_symbol_tab);
#endif

    if (!of_is_decoding_complete(session))
    {
        of_finish_decoding(session);
    }

    free(encoding_symbol_tab);
    of_release_codec_instance(session);
}