Statistics
| Branch: | Revision:

grapes / src / Chunkiser / output-stream-raw.c @ 1c6858bc

History | View | Annotate | Download (1.99 KB)

1
/*
2
 *  Copyright (c) 2010 Luca Abeni
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6

    
7
#include <sys/types.h>
8
#include <sys/stat.h>
9
#include <fcntl.h>
10
#include <unistd.h>
11
#include <stdint.h>
12
#include <stdlib.h>
13
#include <string.h>
14
#include <stdio.h>
15

    
16
#include "payload.h"
17
#include "config.h"
18
#include "dechunkiser_iface.h"
19

    
20
struct output_stream {
21
  int fd;
22
  int payload_type;
23
};
24

    
25
static struct output_stream *raw_open(const char *fname, const char *config)
26
{
27
  struct output_stream *res;
28
  struct tag *cfg_tags;
29

    
30
  res = malloc(sizeof(struct output_stream));
31
  if (res == NULL) {
32
    return NULL;
33
  }
34
  res->fd = 1;
35
  res->payload_type = 0;
36
  if (fname) {
37
    res->fd = open(fname, O_WRONLY | O_CREAT, S_IROTH | S_IWUSR | S_IRUSR);
38
    if (res->fd < 0) {
39
      res->fd = 1;
40
    }
41
  }
42
  cfg_tags = config_parse(config);
43
  if (cfg_tags) {
44
    const char *pt;
45

    
46
    pt = config_value_str(cfg_tags, "payload");
47
    if (pt) {
48
      if (!strcmp(pt, "avf")) {
49
        res->payload_type = 1;
50
      }
51
    }
52
  }
53

    
54
  return res;
55
}
56

    
57
static void raw_write(struct output_stream *o, int id, uint8_t *data, int size)
58
{
59
  int offset;
60

    
61
  if (o->payload_type == 1) {
62
    const int header_size = VIDEO_PAYLOAD_HEADER_SIZE;
63
    int width, height, frame_rate_n, frame_rate_d, frames;
64
    int i;
65
    uint8_t codec;
66

    
67
    payload_header_parse(data, &codec, &width, &height, &frame_rate_n, &frame_rate_d);
68
    if (codec > 127) {
69
      fprintf(stderr, "Error! Non video chunk: %x!!!\n", codec);
70
      return;
71
    }
72
//    dprintf("Frame size: %dx%d -- Frame rate: %d / %d\n", width, height, frame_rate_n, frame_rate_d);
73
    frames = data[9];
74
    for (i = 0; i < frames; i++) {
75
      int frame_size;
76
      int64_t pts, dts;
77

    
78
      frame_header_parse(data, &frame_size, &pts, &dts);
79
//      dprintf("Frame %d has size %d\n", i, frame_size);
80
    }
81
    offset = header_size + frames * FRAME_HEADER_SIZE;
82
  } else {
83
    offset = 0;
84
  }
85

    
86
  write(o->fd, data + offset, size - offset);
87
}
88

    
89
struct dechunkiser_iface out_raw = {
90
  .open = raw_open,
91
  .write = raw_write,
92
};