Revision 421c2dc2

View differences:

Chunkiser/input-stream-avs.c
9 9

  
10 10
#include "../dbg.h"
11 11
#include "../input-stream.h"
12
#include "../payload.h"
12 13
#include "../input.h"		//TODO: for flags. Check if we can do something smarter
14

  
13 15
#define STATIC_BUFF_SIZE 1000 * 1024
14 16
#define HEADER_REFRESH_PERIOD 50
15 17

  
......
23 25
  int frames_since_global_headers;
24 26
};
25 27

  
26
#define VIDEO_PAYLOAD_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
27
#define FRAME_HEADER_SIZE (3 + 4 + 1)	// 3 Frame size + 4 PTS + 1 DeltaTS
28

  
29 28
static uint8_t codec_type(enum CodecID cid)
30 29
{
31 30
  switch (cid) {
input-stream-dummy.c
10 10
#include <string.h>
11 11

  
12 12
#include "input-stream.h"
13

  
14
#define FRAME_HEADER_SIZE (3 + 4 + 1)
13
#include "payload.h"
15 14

  
16 15
static struct input_stream {
17 16
} fake_descriptor;
out-stream-avf.c
9 9

  
10 10
#include "out-stream.h"
11 11
#include "dbg.h"
12
#include "payload.h"
12 13

  
13 14
static const char *output_format = "nut";
14 15
static const char *output_file = "/dev/stdout";
15 16

  
16 17
static int64_t prev_pts, prev_dts;
17 18

  
18
#define VIDEO_PAYLOAD_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
19
#define FRAME_HEADER_SIZE (3 + 4 + 1)
20

  
21
static void frame_header_parse(const uint8_t *data, int *size, int32_t *pts, int32_t *dts)
22
{
23
  int i;
24

  
25
  *size = 0;
26
  for (i = 0; i < 3; i++) {
27
    *size = *size << 8;
28
    *size |= data[i];
29
  }
30
  *pts = 0;
31
  for (i = 0; i < 4; i++) {
32
    *pts = *pts << 8;
33
    *pts |= data[3 + i];
34
  }
35
  *dts = *pts - data[7];
36
}
37

  
38 19
static enum CodecID libav_codec_id(uint8_t mytype)
39 20
{
40 21
  switch (mytype) {
......
76 57
  AVCodecContext *c;
77 58
  AVOutputFormat *outfmt;
78 59
  int width, height, frame_rate_n, frame_rate_d;
60
  uint8_t codec;
79 61

  
80 62
  av_register_all();
81 63

  
82
  width = data[1] << 8 | data[2];
83
  height = data[3] << 8 | data[4];
84
  frame_rate_n = data[5] << 8 | data[6];
85
  frame_rate_d = data[7] << 8 | data[8];
64
  payload_header_parse(data, &codec, &width, &height, &frame_rate_n, &frame_rate_d);
86 65
  dprintf("Frame size: %dx%d -- Frame rate: %d / %d\n", width, height, frame_rate_n, frame_rate_d);
87

  
88 66
  outfmt = av_guess_format(output_format, NULL, NULL);
89 67
  of = avformat_alloc_context();
90 68
  if (of == NULL) {
......
93 71
  of->oformat = outfmt;
94 72
  av_new_stream(of, 0);
95 73
  c = of->streams[0]->codec;
96
  c->codec_id = libav_codec_id(data[0]);
74
  c->codec_id = libav_codec_id(codec);
97 75
  c->codec_type = CODEC_TYPE_VIDEO;
98 76
  c->width = width;
99 77
  c->height= height;
out-stream-dummy.c
4 4

  
5 5
#include "out-stream.h"
6 6
#include "dbg.h"
7
#include "payload.h"
7 8

  
8 9
static int outfd = 1;
9 10

  
10
#define FRAME_HEADER_SIZE (3 + 4 + 1)
11

  
12 11
void chunk_write(int id, const uint8_t *data, int size)
13 12
{
14 13
  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
payload.h
1
#define VIDEO_PAYLOAD_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
2
#define FRAME_HEADER_SIZE (3 + 4 + 1)	// 3 Frame size + 4 PTS + 1 DeltaTS
3

  
4
static inline void frame_header_parse(const uint8_t *data, int *size, int32_t *pts, int32_t *dts)
5
{
6
  int i;
7

  
8
  *size = 0;
9
  for (i = 0; i < 3; i++) {
10
    *size = *size << 8;
11
    *size |= data[i];
12
  }
13
  *pts = 0;
14
  for (i = 0; i < 4; i++) {
15
    *pts = *pts << 8;
16
    *pts |= data[3 + i];
17
  }
18
  *dts = *pts - data[7];
19
}
20

  
21
static inline void payload_header_parse(const uint8_t *data, uint8_t *codec, int *width, int *height, int *frame_rate_n, int *frame_rate_d)
22
{
23
  *codec = data[0];
24
  *width = data[1] << 8 | data[2];
25
  *height = data[3] << 8 | data[4];
26
  *frame_rate_n = data[5] << 8 | data[6];
27
  *frame_rate_d = data[7] << 8 | data[8];
28
}

Also available in: Unified diff