File: encode.c

package info (click to toggle)
schroedinger 1.0.11-2.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,480 kB
  • ctags: 6,139
  • sloc: ansic: 97,380; sh: 11,238; xml: 6,509; makefile: 387
file content (112 lines) | stat: -rw-r--r-- 2,108 bytes parent folder | download | duplicates (3)
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

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <schroedinger/schro.h>
#include <schroedinger/schrodebug.h>


static void
frame_free (SchroFrame *frame, void *priv)
{
  free (priv);
}

static void
test (int w, int h)
{
  int size;
  uint8_t *picture;
  SchroEncoder *encoder;
  SchroBuffer *buffer;
  SchroFrame *frame;
  SchroVideoFormat *format;
  int n_frames;
  int go;

  encoder = schro_encoder_new();
  format = schro_encoder_get_video_format(encoder);
  format->width = w;
  format->height = h;
  format->clean_width = w;
  format->clean_height = h;
  format->left_offset = 0;
  format->top_offset = 0;
  schro_encoder_set_video_format (encoder, format);
  free (format);
  schro_encoder_start (encoder);

  size = ROUND_UP_4 (w) * ROUND_UP_2 (h);
  size += (ROUND_UP_8 (w)/2) * (ROUND_UP_2 (h)/2);
  size += (ROUND_UP_8 (w)/2) * (ROUND_UP_2 (h)/2);

  n_frames = 0;
  go = 1;
  while (go) {
    int x;

    switch (schro_encoder_wait (encoder)) {
      case SCHRO_STATE_NEED_FRAME:
        if (n_frames < 100) {
          //SCHRO_ERROR("frame %d", n_frames);

          picture = malloc(size);
          memset (picture, 128, size);

          frame = schro_frame_new_from_data_I420 (picture, w, h);

          schro_frame_set_free_callback (frame, frame_free, picture);

          schro_encoder_push_frame (encoder, frame);

          n_frames++;
        } else {
          schro_encoder_end_of_stream (encoder);
        }
        break;
      case SCHRO_STATE_HAVE_BUFFER:
        buffer = schro_encoder_pull (encoder, &x);
        //printf("%d\n", x);
        schro_buffer_unref (buffer);
        break;
      case SCHRO_STATE_AGAIN:
        break;
      case SCHRO_STATE_END_OF_STREAM:
        go = 0;
        break;
      default:
        break;
    }
  }

  schro_encoder_free (encoder);
}

#define SIZE 128

int
main (int argc, char *argv[])
{
  int h, w;


  schro_init();

  test(853,480);
  if (0) {
    for(w=SIZE;w<SIZE+16;w++){
      for(h=SIZE;h<SIZE+16;h++){
        test(w,h);
      }
    }
  }

  return 0;
}