File: p_index.cpp

package info (click to toggle)
ogmtools 1%3A1.5-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,564 kB
  • sloc: cpp: 8,003; ansic: 5,865; sh: 3,167; makefile: 71
file content (130 lines) | stat: -rw-r--r-- 3,021 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
  ogmmerge -- utility for splicing together ogg bitstreams
      from component media subtypes

  p_index.cpp
  video index

  Written by Moritz Bunkus <moritz@bunkus.org>
  Based on Xiph.org's 'oggmerge' found in their CVS repository
  See http://www.xiph.org

  Distributed under the GPL
  see the file COPYING for details
  or visit http://www.gnu.org/copyleft/gpl.html
*/

#ifdef ENABLE_INDEX

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include <ogg/ogg.h>

#include "ogmmerge.h"
#include "queue.h"
#include "p_index.h"
#include "vorbis_header_utils.h"

index_packetizer_c::index_packetizer_c(int nserial) throw (error_c) : q_c() {
  serialno = create_unique_serial();
  ogg_stream_init(&os, serialno);
  granulepos = 0;
  serial = nserial;
  packetno = 0;
  produce_header_packets();
}

index_packetizer_c::~index_packetizer_c() {
}

void index_packetizer_c::reset() {
}

void index_packetizer_c::produce_header_packets() {
  ogg_packet      op;
  stream_header   sh;
  int             clen, res;
  char           *tempbuf;
  vorbis_comment *vc;

  tempbuf = (char *)malloc(sizeof(sh) + 64);
  if (tempbuf == NULL)
    die("malloc");
  memset(&sh, 0, sizeof(sh));
  strcpy(sh.streamtype, "index");
  put_uint32(&sh.subtype[0], serial);
  put_uint32(&sh.size, sizeof(sh));
  put_uint64(&sh.time_unit, 10000000);

  *((unsigned char *)tempbuf) = PACKET_TYPE_HEADER;
  memcpy((char *)&tempbuf[1], &sh, sizeof(sh));
  op.packet = (unsigned char *)tempbuf;
  op.bytes = 1 + get_uint32(&sh.size);
  op.b_o_s = 1;
  op.e_o_s = 0;
  op.packetno = 0;
  op.granulepos = 0;
  /* submit it */
  ogg_stream_packetin(&os, &op);
  packetno++;
  flush_pages(PACKET_TYPE_HEADER);

  /* Create the comments packet */
  vc = generate_vorbis_comment(NULL);
  clen = -1 * comments_to_buffer(vc, NULL, 0);
  op.packet = (unsigned char *)tempbuf;
  op.bytes = clen;
  op.b_o_s = 0;
  op.e_o_s = 0;
  op.granulepos = 0;
  op.packetno = 1;
  if ((res = comments_to_buffer(vc, (char *)op.packet, clen)) < 0) {
    fprintf(stderr, "FATAL: p_index: comments_to_buffer returned %d, " \
            "clen is %d\n", res, clen);
    exit(1);
  }
  ogg_stream_packetin(&os, &op);
  flush_pages(PACKET_TYPE_COMMENT);
  packetno++;
  vorbis_comment_clear(vc);
  free(vc);
}

int index_packetizer_c::process(idx_entry *entries, int num) {
  ogg_packet op;
  char *tempbuf;

  tempbuf = (char *)malloc(num * sizeof(idx_entry) + 64);
  if (tempbuf == NULL)
    die("malloc");

  this->serial = serial;

  memcpy(&tempbuf[1], entries, num * sizeof(idx_entry));
  tempbuf[0] = PACKET_IS_SYNCPOINT;
  op.bytes = num * sizeof(idx_entry) + 1;
  op.packet = (unsigned char *)tempbuf;
  op.b_o_s = 0;
  op.e_o_s = 1;
  op.granulepos = 0;
  op.packetno = packetno++;
  ogg_stream_packetin(&os, &op);
  
  flush_pages();

  free(tempbuf);

  return EMOREDATA;
}

void index_packetizer_c::produce_eos_packet() {
}
  
stamp_t index_packetizer_c::make_timestamp(ogg_int64_t granulepos) {
  return 0;
}

#endif // ENABLE_INDEX