File: oggplay-info.c

package info (click to toggle)
liboggplay 0.2.1~git20091227-1.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,988 kB
  • sloc: sh: 10,215; ansic: 6,192; makefile: 214
file content (188 lines) | stat: -rw-r--r-- 4,679 bytes parent folder | download | duplicates (4)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "config.h"

#include <oggplay/oggplay.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

static int n_frames = 0;

typedef struct {
  int     last_overrun;
  int     worst_overrun;
  int     overrun_sum;
  int   * histogram;
} overrunInfo;

static overrunInfo *overruns = NULL;

int
dump_streams_callback(OggPlay *player, int num_records, 
                      OggPlayCallbackInfo **info, void *user) {

  int                   i;
  int                   available;
  int                   required;
  int                   overrun;
  OggPlayDataHeader  ** headers;

  if (overruns == NULL) {
    overruns = malloc (sizeof (overrunInfo) * num_records);
    for (i = 0; i < num_records; i++) {
      overruns[i].last_overrun = 0;
      overruns[i].worst_overrun = 0;
      overruns[i].overrun_sum = 0;
      overruns[i].histogram = malloc (sizeof (int));
      overruns[i].histogram[0] = 0;
    }
  }
  
  for (i = 0; i < num_records; i++)
  {

    int j;

    required = oggplay_callback_info_get_required(info[i]);
    available = oggplay_callback_info_get_available(info[i]);
    headers = oggplay_callback_info_get_headers(info[i]);

    overrun = 0;
    for (j = required; j < available; j++) {
      /*OggPlayDataHeader *header;*/

      overrun += oggplay_callback_info_get_record_size(headers[j]);

    }
    
    if (overrun > overruns[i].worst_overrun) {
      int j;
      overruns[i].histogram = realloc (overruns[i].histogram, 
                                        (overrun + 1) * sizeof (int));
      for (j = overruns[i].worst_overrun + 1; j <= overrun; j++) {
        overruns[i].histogram[j] = 0;
      }

      overruns[i].worst_overrun = overrun;
    }

    overruns[i].overrun_sum += overrun;

    overruns[i].histogram[overrun] += 1;

    overruns[i].last_overrun = overrun;
    
    printf("track %d required %d times [", i, required);
    for (j = 0; j < required; j++) {
      if (j > 0) {
        printf(", ");
      }
      printf("%ld", oggplay_callback_info_get_presentation_time(headers[j]));
    }
    printf("] ");
    
  }
  printf("\n");
  
  n_frames += 1;

  return 0;
}

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

  OggPlay       * player;
  OggPlayReader * reader;
  int             i;

  if (argc < 2) {
    printf ("please provide a filename\n");
    exit (1);
  }
  
  reader = oggplay_file_reader_new(argv[1]);

  player = oggplay_open_with_reader(reader);

  if (player == NULL) {
    printf ("could not initialise oggplay with this file\n");
    exit (1);
  }

  printf ("Reading %d tracks ...\n", oggplay_get_num_tracks (player));
  
  for (i = 0; i < oggplay_get_num_tracks (player); i++) {
    printf("\t%s: Track %d ...", oggplay_get_track_typename (player, i), i);
    if (oggplay_get_track_type (player, i) == OGGZ_CONTENT_THEORA) {
      oggplay_set_callback_num_frames (player, i, 1);
    }
    /*
    if (oggplay_get_track_type (player, i) == OGGZ_CONTENT_VORBIS) {
      oggplay_set_offset(player, i, 1000LL);
    }
    */

    if (oggplay_set_track_active(player, i) < 0) {
      printf(" Could not set this track active!\n");
    } else {
      printf(" ok ...\n");
    }
  }

  oggplay_set_data_callback(player, dump_streams_callback, NULL);
  oggplay_start_decoding(player);

  printf("Total %d frames.\n", n_frames);
 
  if (n_frames == 0)
    return 0;

  for (i = 0; i < oggplay_get_num_tracks (player); i++) {
    int j;
    long long mse = 0;
    
    double average = (double)(overruns[i].overrun_sum)/n_frames;
    double hist_bucket_size;
    double cur_bucket;

    if (overruns[i].worst_overrun > 30)
      hist_bucket_size =  overruns[i].worst_overrun/20.0;
    else
      hist_bucket_size = 1.0;
    
    printf("\n%s: Track %d\n", oggplay_get_track_typename (player, i), i);
    printf("\tWorst overrun: %d frames\n", overruns[i].worst_overrun);
    printf("\tAverage overrun: %.3f frames\n", average);
    printf("\tHistogram bucket size: %.3f\n", hist_bucket_size);
    printf("\tHistogram:");

    for 
    (
      cur_bucket = 0; 
      cur_bucket <= overruns[i].worst_overrun; 
      cur_bucket += hist_bucket_size
    ) {
      int sum = 0;
      //printf(" (%f-%f)", cur_bucket, cur_bucket + hist_bucket_size);
      for 
      (
        j = ceil(cur_bucket); 
        j < (cur_bucket + hist_bucket_size) && j <= overruns[i].worst_overrun; 
        j++
      ) {
        sum += overruns[i].histogram[j];
      }
      printf(" %d", sum);
    }

    for (j = 0; j <= overruns[i].worst_overrun; j++) {
      mse += (average - j) * (average - j) * overruns[i].histogram[j];
    }
    printf("\n");
    printf("\tSD of overrun: %f\n", sqrt(mse/n_frames));

            
  }

  return 0;
}