Exemple #1
0
OggzDList *
oggz_dlist_new (void) {

  OggzDList *dlist;
  OggzDListElem *dummy_front, *dummy_back;
  
  dlist = oggz_malloc(sizeof(OggzDList));
  if (dlist == NULL) return NULL;

  dummy_front = oggz_malloc(sizeof(OggzDListElem));
  if (dummy_front == NULL) {
    oggz_free (dlist);
    return NULL;
  }

  dummy_back = oggz_malloc(sizeof(OggzDListElem));
  if (dummy_back == NULL) {
    oggz_free (dummy_front);
    oggz_free (dlist);
    return NULL;
  }

  dummy_front->next = dummy_back;
  dummy_front->prev = NULL;

  dummy_back->prev = dummy_front;
  dummy_back->next = NULL;

  dlist->head = dummy_front;
  dlist->tail = dummy_back;

  return dlist;
}
Exemple #2
0
oggz_stream_t *
oggz_add_stream (OGGZ * oggz, long serialno)
{
  oggz_stream_t * stream;

  stream = oggz_malloc (sizeof (oggz_stream_t));
  if (stream == NULL) return NULL;

  ogg_stream_init (&stream->ogg_stream, (int)serialno);

  stream->delivered_non_b_o_s = 0;
  stream->b_o_s = 1;
  stream->e_o_s = 0;
  stream->granulepos = 0;
  stream->packetno = -1; /* will be incremented on first write */

  stream->metric = NULL;
  stream->metric_user_data = NULL;
  stream->metric_internal = 0;
  stream->order = NULL;
  stream->order_user_data = NULL;
  stream->read_packet = NULL;
  stream->read_user_data = NULL;

  oggz_vector_insert_p (oggz->streams, stream);

  return stream;
}
Exemple #3
0
OGGZ *
oggz_new (int flags)
{
  OGGZ * oggz;

  if (oggz_flags_disabled (flags)) return NULL;

  oggz = (OGGZ *) oggz_malloc (sizeof (OGGZ));
  if (oggz == NULL) return NULL;

  oggz->flags = flags;
  oggz->file = NULL;
  oggz->io = NULL;

  oggz->offset = 0;
  oggz->offset_data_begin = 0;

  oggz->streams = oggz_vector_new ();
  oggz->all_at_eos = 0;

  oggz->metric = NULL;
  oggz->metric_user_data = NULL;
  oggz->metric_internal = 0;

  oggz->order = NULL;
  oggz->order_user_data = NULL;

  if (OGGZ_CONFIG_WRITE && (oggz->flags & OGGZ_WRITE)) {
    oggz_write_init (oggz);
  } else if (OGGZ_CONFIG_READ) {
    oggz_read_init (oggz);
  }

  return oggz;
}
static OggzComment *
oggz_comment_new (const char * name, const char * value)
{
  OggzComment * comment;

  if (!oggz_comment_validate_byname (name)) return NULL;
  /* Ensures that name != NULL and contains only valid characters */

  comment = oggz_malloc (sizeof (OggzComment));
  if (comment == NULL) return NULL;

  comment->name = oggz_strdup (name);
  if (comment->name == NULL) {
    oggz_free (comment);
    return NULL;
  }

  if (value) {
    comment->value = oggz_strdup (value);
    if (comment->value == NULL) {
      oggz_free (comment->name);
      oggz_free (comment);
      return NULL;
    }
  } else {
    comment->value = NULL;
  }

  return comment;
}
Exemple #5
0
static char *
oggz_strdup (const char * s)
{
    char * ret;
    if (s == NULL) return NULL;
    ret = oggz_malloc (strlen(s) + 1);
    return strcpy (ret, s);
}
Exemple #6
0
static int
oggz_io_init (OGGZ * oggz)
{
  oggz->io = (OggzIO *) oggz_malloc (sizeof (OggzIO));
  if (oggz->io == NULL) return -1;

  memset (oggz->io, 0, sizeof (OggzIO));

  return 0;
}
Exemple #7
0
OggzTable *
oggz_table_new (void)
{
  OggzTable * table;

  table = oggz_malloc (sizeof (OggzTable));
  table->keys = oggz_vector_new ();
  table->data = oggz_vector_new ();

  return table;
}
Exemple #8
0
static OggzComment *
oggz_comment_new (const char * name, const char * value)
{
    OggzComment * comment;

    if (!oggz_comment_validate_byname (name, value)) return NULL;

    comment = oggz_malloc (sizeof (OggzComment));
    comment->name = oggz_strdup (name);
    comment->value = oggz_strdup (value);

    return comment;
}
Exemple #9
0
static void
comment_init(char **comments, int* length, char *vendor_string)
{
    int vendor_length=strlen(vendor_string);
    int user_comment_list_length=0;
    int len=4+vendor_length+4;
    char *p=(char*)oggz_malloc(len);
    if(p==NULL) {
    }
    writeint(p, 0, vendor_length);
    memcpy(p+4, vendor_string, vendor_length);
    writeint(p, 4+vendor_length, user_comment_list_length);
    *length=len;
    *comments=p;
}
Exemple #10
0
static char *
oggz_strdup_len (const char * s, int len)
{
    char * ret;
    if (s == NULL) return NULL;
    if (len == 0) return NULL;
    ret = oggz_malloc (len + 1);
    if (!ret) return NULL;
    if (strncpy (ret, s, len) == NULL) {
        oggz_free (ret);
        return NULL;
    }

    ret[len] = '\0';
    return ret;
}
Exemple #11
0
int
oggz_dlist_prepend(OggzDList *dlist, void *elem) {

  OggzDListElem *new_elem;

  if (dlist == NULL) return -1;

  new_elem = oggz_malloc(sizeof(OggzDListElem));
  if (new_elem == NULL) return -1;

  new_elem->data = elem;
  new_elem->prev = dlist->head;
  new_elem->next = dlist->head->next;
  new_elem->prev->next = new_elem;
  new_elem->next->prev = new_elem;

  return 0;
}
Exemple #12
0
int
oggz_dlist_append(OggzDList *dlist, void *elem) {

  OggzDListElem *new_elem;

  if (dlist == NULL) return -1;

  new_elem = (OggzDListElem *)oggz_malloc(sizeof(OggzDListElem));
  if (new_elem == NULL) return -1;

  new_elem->data = elem;
  new_elem->next = dlist->tail;
  new_elem->prev = dlist->tail->prev;
  new_elem->prev->next = new_elem;
  new_elem->next->prev = new_elem;

  return 0;
}
Exemple #13
0
oggz_stream_t *
oggz_add_stream (OGGZ * oggz, long serialno)
{
  oggz_stream_t * stream;

  stream = oggz_malloc (sizeof (oggz_stream_t));
  if (stream == NULL) return NULL;

  ogg_stream_init (&stream->ogg_stream, (int)serialno);

  oggz_comments_init (stream);

  stream->content = OGGZ_CONTENT_UNKNOWN;
  stream->numheaders = 3; /* Default to 3 headers for Ogg logical bitstreams */
  stream->preroll = 0;
  stream->granulerate_n = 1;
  stream->granulerate_d = 1;
  stream->basegranule = 0;
  stream->granuleshift = 0;

  stream->delivered_non_b_o_s = 0;
  stream->b_o_s = 1;
  stream->e_o_s = 0;
  stream->granulepos = 0;
  stream->packetno = -1; /* will be incremented on first read or write */

  stream->metric = NULL;
  stream->metric_user_data = NULL;
  stream->metric_internal = 0;
  stream->order = NULL;
  stream->order_user_data = NULL;
  stream->read_packet = NULL;
  stream->read_user_data = NULL;
  stream->read_page = NULL;
  stream->read_page_user_data = NULL;

  stream->calculate_data = NULL;
  
  oggz_vector_insert_p (oggz->streams, stream);

  return stream;
}
Exemple #14
0
int
oggz_set_metric_linear (OGGZ * oggz, long serialno,
			ogg_int64_t granule_rate_numerator,
			ogg_int64_t granule_rate_denominator)
{
  oggz_metric_linear_t * linear_data;

  /* we divide by the granulerate, ie. mult by gr_d/gr_n, so ensure
   * numerator is non-zero */
  if (granule_rate_numerator == 0) {
    granule_rate_numerator = 1;
    granule_rate_denominator = 0;
  }

  linear_data = oggz_malloc (sizeof (oggz_metric_linear_t));
  linear_data->gr_n = granule_rate_numerator;
  linear_data->gr_d = granule_rate_denominator;

  return oggz_set_metric_internal (oggz, serialno, oggz_metric_default_linear,
				   linear_data, 1);
}
Exemple #15
0
static int
auto_theora (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
{
  unsigned char * header = op->packet;
  char keyframe_granule_shift = 0;
  oggz_theora_metric_t * tdata;

  if (op->bytes < 41) return 0;

  if (header[0] != 0x80) return 0;
  if (strncmp ((char *)&header[1], "theora", 6)) return 0;
  if (!op->b_o_s) return 0;


  tdata = oggz_malloc (sizeof (oggz_theora_metric_t));

  tdata->fps_numerator = INT32_BE_AT(&header[22]);
  tdata->fps_denominator = INT32_BE_AT(&header[26]);

#if USE_THEORA_PRE_ALPHA_3_FORMAT
  /* old header format, used by Theora alpha2 and earlier */
  keyframe_granule_shift = (header[36] & 0xf8) >> 3;
#else
  keyframe_granule_shift = (header[40] & 0x03) << 3;
  keyframe_granule_shift |= (header[41] & 0xe0) >> 5;
#endif
  tdata->keyframe_shift = intlog (keyframe_granule_shift - 1);

#ifdef DEBUG
  printf ("Got theora fps %d/%d, keyframe_granule_shift %d\n",
	  tdata->fps_numerator, tdata->fps_denominator,
	  keyframe_granule_shift);
#endif

  /*oggz_set_metric_internal (oggz, serialno, auto_theora_metric, tdata, 1);*/
  oggz_set_metric (oggz, serialno, auto_theora_metric, tdata);

  return 1;
}
/* NB. Public use of this function is deprecated; the simpler
 * oggz_comments_generate() automatically determines the packet_type */
ogg_packet *
oggz_comment_generate(OGGZ * oggz, long serialno,
		      OggzStreamContent packet_type,
		      int FLAC_final_metadata_block)
{
  ogg_packet *c_packet;

  unsigned char *buffer;
  unsigned const char *preamble;
  long preamble_length, comment_length, buf_size;

  /* Some types use preambles in the comment packet. FLAC is notable;
     n9-32 should contain the length of the comment data as 24bit unsigned
     BE, and the first octet should be ORed with 0x80 if this is the last
     (only) metadata block. Any user doing FLAC has to know how to do the
     encapsulation anyway. */
  const unsigned char preamble_vorbis[7] =
    {0x03, 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73};
  const unsigned char preamble_theora[7] =
    {0x81, 0x74, 0x68, 0x65, 0x6f, 0x72, 0x61};
  const unsigned char preamble_flac[4] =
    {0x04, 0x00, 0x00, 0x00};
  const unsigned char preamble_kate[9] =
    {0x81, 0x6b, 0x61, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00};


  switch(packet_type) {
    case OGGZ_CONTENT_VORBIS:
      preamble_length = sizeof preamble_vorbis;
      preamble = preamble_vorbis;
      break;
    case OGGZ_CONTENT_THEORA:
      preamble_length = sizeof preamble_theora;
      preamble = preamble_theora;
      break;
    case OGGZ_CONTENT_FLAC:
      preamble_length = sizeof preamble_flac;
      preamble = preamble_flac;
      break;
    case OGGZ_CONTENT_KATE:
      preamble_length = sizeof preamble_kate;
      preamble = preamble_kate;
      break;
    case OGGZ_CONTENT_PCM:
    case OGGZ_CONTENT_SPEEX:
      preamble_length = 0;
      preamble = 0;
      /* No preamble for these */
      break;
    default:
      return NULL;
  }

  comment_length = oggz_comments_encode (oggz, serialno, 0, 0);
  if(comment_length <= 0) {
    return NULL;
  }

  buf_size = preamble_length + comment_length;

  if(packet_type == OGGZ_CONTENT_FLAC && comment_length >= 0x00ffffff) {
    return NULL;
  }

  c_packet = oggz_malloc(sizeof *c_packet);
  if(c_packet) {
    memset(c_packet, 0, sizeof *c_packet);
    c_packet->packetno = 1;
    c_packet->packet = oggz_malloc(buf_size);
  }

  if(c_packet && c_packet->packet) {
    buffer = c_packet->packet;
    if(preamble_length) {
      memcpy(buffer, preamble, preamble_length);
      if(packet_type == OGGZ_CONTENT_FLAC) {
	/* Use comment_length-1 as we will be stripping the Vorbis
	   framing byte. */
	/* MACRO */
	writeint24be(c_packet->packet, 1, (comment_length-1) );
	if(FLAC_final_metadata_block) 
	  {
	    c_packet->packet[0] |= 0x80;
	  }
      }
      buffer += preamble_length;
    }
    oggz_comments_encode (oggz, serialno, buffer, comment_length);
    c_packet->bytes = buf_size;
    /* The framing byte for Vorbis shouldn't affect any of the other
       types, but strip it anyway. */
    if(packet_type != OGGZ_CONTENT_VORBIS)
      {
	c_packet->bytes -= 1;
      }
  } else {
    oggz_free(c_packet);
    c_packet = 0;
  }

  return c_packet;
}