Revision a83e9f0b src/Chunkiser/input-stream-ipb.c

View differences:

src/Chunkiser/input-stream-ipb.c
15 15
#include "chunkiser_iface.h"
16 16

  
17 17
#define STATIC_BUFF_SIZE 1000 * 1024
18

  
19
struct log_info {
20
  int i_frames[16];
21
  int p_frames[16];
22
  int b_frames[16];
23
  int frame_number;
24
  FILE *log;
25
};
26

  
18 27
struct chunkiser_ctx {
19 28
  AVFormatContext *s;
20 29
  int loop;	//loop on input file infinitely
......
30 39
  int p_ready;
31 40
  int b_ready;
32 41
  AVBitStreamFilterContext *bsf[MAX_STREAMS];
42

  
43
  struct log_info chunk_log;
33 44
};
34 45

  
46
static void chunk_print(FILE *log, int id, int *frames)
47
{
48
  int i = 0;
49

  
50
  fprintf(log, "Chunk %d:", id);
51
  while (frames[i] != -1) {
52
    fprintf(log, " %d", frames[i++]);
53
  }
54
  fprintf(log, "\n");
55
  frames[0] = -1;
56
}
57

  
58
static void frame_add(int *frames, int frame_id)
59
{
60
  int i = 0;
61

  
62
  while (frames[i] != -1) i++;
63
  frames[i] = frame_id;
64
  frames[i + 1] = -1;
65
}
66

  
35 67
static int frame_type(AVPacket *pkt)
36 68
{
37 69
  if ((pkt->dts == AV_NOPTS_VALUE) || (pkt->pts == AV_NOPTS_VALUE)) {
......
189 221
  desc->b_chunk_size = 0;
190 222
  desc->p_ready = 0;
191 223
  desc->b_ready = 0;
224
  desc->chunk_log.i_frames[0] = -1;
225
  desc->chunk_log.p_frames[0] = -1;
226
  desc->chunk_log.b_frames[0] = -1;
227
  desc->chunk_log.frame_number = 0;
228
  desc->chunk_log.log = fopen("chunk_log.txt", "w");
192 229
  cfg_tags = config_parse(config);
193 230
  if (cfg_tags) {
194 231
    const char *media;
......
252 289
  free(s->i_chunk);
253 290
  free(s->p_chunk);
254 291
  free(s->b_chunk);
292
  fclose(s->chunk_log.log);
255 293
  free(s);
256 294
}
257 295

  
......
292 330

  
293 331
    return NULL;
294 332
  }
333
  s->chunk_log.frame_number++;
295 334
  if (s->bsf[pkt.stream_index]) {
296 335
    AVPacket new_pkt= pkt;
297 336
    int res;
......
324 363
      fprintf(stderr, "I Frame!\n");
325 364
      result = s->i_chunk;
326 365
      *size = s->i_chunk_size;
366
      if (*size) chunk_print(s->chunk_log.log, id, s->chunk_log.i_frames);
327 367
      s->i_chunk = NULL;
328 368
      s->p_ready = 1;
329 369
      s->b_ready = 1;
330 370
      if (s->i_chunk == NULL) {
371

  
331 372
        s->i_chunk = malloc(VIDEO_PAYLOAD_HEADER_SIZE);
332 373
        s->i_chunk_size = VIDEO_PAYLOAD_HEADER_SIZE;
333 374
        video_header_fill(s->i_chunk, s->s->streams[pkt.stream_index]);
334 375
      }
376
      frame_add(s->chunk_log.i_frames, s->chunk_log.frame_number);
335 377
      s->i_chunk_size += pkt.size + FRAME_HEADER_SIZE;
336 378
      s->i_chunk = realloc(s->i_chunk, s->i_chunk_size);
337 379
      data = s->i_chunk + (s->i_chunk_size - (pkt.size + FRAME_HEADER_SIZE));
......
343 385
        *size = s->p_chunk_size;
344 386
        s->p_chunk = NULL;
345 387
        s->p_ready = 0;
388
        if (*size) chunk_print(s->chunk_log.log, id, s->chunk_log.p_frames);
346 389
      }
347 390
      if (s->p_chunk == NULL) {
348 391
        s->p_chunk = malloc(VIDEO_PAYLOAD_HEADER_SIZE);
349 392
        s->p_chunk_size = VIDEO_PAYLOAD_HEADER_SIZE;
350 393
        video_header_fill(s->p_chunk, s->s->streams[pkt.stream_index]);
351 394
      }
395
      frame_add(s->chunk_log.p_frames, s->chunk_log.frame_number);
352 396
      s->p_chunk_size += pkt.size + FRAME_HEADER_SIZE;
353 397
      s->p_chunk = realloc(s->p_chunk, s->p_chunk_size);
354 398
      data = s->p_chunk + (s->p_chunk_size - (pkt.size + FRAME_HEADER_SIZE));
......
360 404
        *size = s->b_chunk_size;
361 405
        s->b_chunk = NULL;
362 406
        s->b_ready = 0;
407
        if (*size) chunk_print(s->chunk_log.log, id, s->chunk_log.b_frames);
363 408
      }
364 409
      if (s->b_chunk == NULL) {
365 410
        s->b_chunk = malloc(VIDEO_PAYLOAD_HEADER_SIZE);
366 411
        s->b_chunk_size = VIDEO_PAYLOAD_HEADER_SIZE;
367 412
        video_header_fill(s->b_chunk, s->s->streams[pkt.stream_index]);
368 413
      }
414
      frame_add(s->chunk_log.b_frames, s->chunk_log.frame_number);
369 415
      s->b_chunk_size += pkt.size + FRAME_HEADER_SIZE;
370 416
      s->b_chunk = realloc(s->b_chunk, s->b_chunk_size);
371 417
      data = s->b_chunk + (s->b_chunk_size - (pkt.size + FRAME_HEADER_SIZE));

Also available in: Unified diff