Revision 74ff12bb

View differences:

Chunkiser/input-stream-avs.c
188 188
    }
189 189

  
190 190
    if (s->s->streams[pkt.stream_index]->codec->codec_type == CODEC_TYPE_VIDEO) {
191
      header_size = 1 + 2 + 2 + 1 + 2; // 1 Frame type + 2 width + 2 height + 1 number of frames + 2 frame len
191
      header_size = 1 + 2 + 2 + 2 + 2 + 1; // 1 Frame type + 2 width + 2 height + 2 frame rate num + 2 frame rate den + 1 number of frames
192 192
    }
193 193
    header_out = (pkt.flags & PKT_FLAG_KEY) != 0;
194 194
    if (header_out == 0) {
......
198 198
        header_out = 1;
199 199
      }
200 200
    }
201
    *size = pkt.size + s->s->streams[pkt.stream_index]->codec->extradata_size * header_out + header_size;
201
    *size = pkt.size + s->s->streams[pkt.stream_index]->codec->extradata_size * header_out + header_size + 2;
202 202
    data = malloc(*size);
203 203
    if (data == NULL) {
204 204
      *size = -1;
......
207 207
      return NULL;
208 208
    }
209 209
    if (s->s->streams[pkt.stream_index]->codec->codec_type == CODEC_TYPE_VIDEO) {
210
      int num, den;
211

  
210 212
      data[0] = 1;
211 213
      data[1] = s->s->streams[pkt.stream_index]->codec->width >> 8;
212 214
      data[2] = s->s->streams[pkt.stream_index]->codec->width & 0xFF;
213 215
      data[3] = s->s->streams[pkt.stream_index]->codec->height >> 8;
214 216
      data[4] = s->s->streams[pkt.stream_index]->codec->height & 0xFF;
215
      data[5] = 1;
216
      data[6] = (*size - header_size) >> 8;
217
      data[7] = (*size - header_size) & 0xFF;
217
      num = s->s->streams[pkt.stream_index]->avg_frame_rate.num;
218
      den = s->s->streams[pkt.stream_index]->avg_frame_rate.den;
219
//fprintf(stderr, "Rate: %d/%d\n", num, den);
220
      if (num == 0) {
221
        num = s->s->streams[pkt.stream_index]->r_frame_rate.num;
222
        den = s->s->streams[pkt.stream_index]->r_frame_rate.den;
223
      }
224
      if (num > (1 << 16)) {
225
        num /= 1000;
226
        den /= 1000;
227
      }
228
      data[5] = num >> 8;
229
      data[6] = num & 0xFF;
230
      data[7] = den >> 8;
231
      data[8] = den & 0xFF;
232
      data[9] = 1;
233
      data[10] = (*size - header_size - 2) >> 8;
234
      data[11] = (*size - header_size - 2) & 0xFF;
218 235
    }
219 236
    if (header_out && s->s->streams[pkt.stream_index]->codec->extradata_size) {
220
      memcpy(data + header_size, s->s->streams[pkt.stream_index]->codec->extradata, s->s->streams[pkt.stream_index]->codec->extradata_size);
221
      memcpy(data + header_size + s->s->streams[pkt.stream_index]->codec->extradata_size, pkt.data, pkt.size);
237
      memcpy(data + header_size + 2, s->s->streams[pkt.stream_index]->codec->extradata, s->s->streams[pkt.stream_index]->codec->extradata_size);
238
      memcpy(data + header_size + 2 + s->s->streams[pkt.stream_index]->codec->extradata_size, pkt.data, pkt.size);
222 239
    } else {
223
      memcpy(data + header_size, pkt.data, pkt.size);
240
      memcpy(data + header_size + 2, pkt.data, pkt.size);
224 241
    }
225 242
    *ts = av_rescale_q(pkt.dts, s->s->streams[pkt.stream_index]->time_base, AV_TIME_BASE_Q);
226 243
    *ts += s->base_ts;
input-stream-dummy.c
27 27
uint8_t *chunkise(struct input_stream *dummy, int id, int *size, uint64_t *ts)
28 28
{
29 29
  uint8_t *res;
30
  const int header_size = 1 + 2 + 2 + 1 + 2; // 1 Frame type + 2 width + 2 height + 1 number of frames + 2 frame len
30
  const int header_size = 1 + 2 + 2 + 2 + 2 + 1; // 1 Frame type + 2 width + 2 height + 2 frame rate num + 2 frame rate den + 1 number of frames
31 31
  static char buff[80];
32 32

  
33 33
  sprintf(buff, "Chunk %d", id);
34 34
  *ts = 40 * id * 1000;
35
  *size = strlen(buff) + 1 + header_size;
35
  *size = strlen(buff) + 1 + header_size + 2;
36 36
  res = malloc(*size);
37 37
  res[0] = 1;
38 38
  res[1] = 352 >> 8;
39 39
  res[2] = 352 & 0xFF;
40 40
  res[3] = 288 >> 8;
41 41
  res[4] = 288 & 0xFF;
42
  res[5] = 1;
43
  res[6] = (*size - header_size) >> 8;
44
  res[7] = (*size - header_size) & 0xFF;
45
  memcpy(res + header_size, buff, *size - header_size);
42
  res[5] = 0;
43
  res[6] = 1;
44
  res[7] = 0;
45
  res[8] = 25;
46
  res[9] = 1;
47
  res[10] = (*size - header_size - 2) >> 8;
48
  res[11] = (*size - header_size - 2) & 0xFF;
49
  memcpy(res + header_size + 2, buff, *size - header_size - 2);
46 50

  
47 51
  return res;
48 52
}
out-stream.c
9 9

  
10 10
void chunk_write(int id, const uint8_t *data, int size)
11 11
{
12
  const int header_size = 1 + 2 + 2 + 1 + 2; // 1 Frame type + 2 width + 2 height + 1 number of frames + 2 frame len
13
  int width, height, frames;
12
  const int header_size = 1 + 2 + 2 + 2 + 2 + 1; // 1 Frame type + 2 width + 2 height + 2 frame rate num + 2 frame rate den + 1 number of frames
13
  int width, height, frame_rate_n, frame_rate_d, frames;
14 14
  int i;
15 15

  
16 16
  if (data[0] != 1) {
17
    fprintf(stderr, "Error! Non video chunk!!!\n");
17
    fprintf(stderr, "Error! Non video chunk: %x!!!\n", data[0]);
18 18
    return;
19 19
  }
20 20
  width = data[1] << 8 | data[2];
21 21
  height = data[3] << 8 | data[4];
22
  dprintf("Frame size: %dx%d\n", width, height);
23
  frames = data[5];
22
  frame_rate_n = data[5] << 8 | data[6];
23
  frame_rate_d = data[7] << 8 | data[8];
24
  dprintf("Frame size: %dx%d -- Frame rate: %d / %d\n", width, height, frame_rate_n, frame_rate_d);
25
  frames = data[9];
24 26
  for (i = 0; i < frames; i++) {
25
    dprintf("Frame %d has size %d\n", i, data[6 + 2 * i] << 8 | data[7 + 2 * i]);
27
    dprintf("Frame %d has size %d\n", i, data[10 + 2 * i] << 8 | data[11 + 2 * i]);
26 28
  }
27 29
#ifdef DEBUG
28 30
#define buff_size 8 // HACK!
29
  fprintf(stderr, "\tOut Chunk[%d] - %d: %s\n", id, id % buff_size, data + header_size);
31
  fprintf(stderr, "\tOut Chunk[%d] - %d: %s\n", id, id % buff_size, data + header_size + frames * 2);
30 32
#else
31
  write(outfd, data + header_size, size - header_size);
33
  write(outfd, data + header_size + frames * 2, size - header_size - frames * 2);
32 34
#endif
33 35
}

Also available in: Unified diff