Revision 46c24e94 Chunkiser/input-stream-avs.c

View differences:

Chunkiser/input-stream-avs.c
5 5
 */
6 6

  
7 7
#include <libavformat/avformat.h>
8
#include <stdbool.h>
8 9

  
9 10
#include "../input-stream.h"
11
#include "../input.h"		//TODO: for flags. Check if we can do something smarter
10 12
#define STATIC_BUFF_SIZE 1000 * 1024
11 13
#define HEADER_REFRESH_PERIOD 50
12 14

  
13 15
struct input_stream {
14 16
  AVFormatContext *s;
17
  bool loop;	//loop on input file infinitely
15 18
  int audio_stream;
16 19
  int video_stream;
17 20
  int64_t last_ts;
......
19 22
  int frames_since_global_headers;
20 23
};
21 24

  
22
struct input_stream *input_stream_open(const char *fname, int *period)
25
struct input_stream *input_stream_open(const char *fname, int *period, uint16_t flags)
23 26
{
24 27
  struct input_stream *desc;
25 28
  int i, res;
......
49 52
  desc->last_ts = 0;
50 53
  desc->base_ts = 0;
51 54
  desc->frames_since_global_headers = 0;
55
  desc->loop = flags & INPUT_LOOP;
52 56
  for (i = 0; i < desc->s->nb_streams; i++) {
53 57
    if (desc->video_stream == -1 && desc->s->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {
54 58
      desc->video_stream = i;
......
162 166

  
163 167
    res = av_read_frame(s->s, &pkt);
164 168
    if (res < 0) {
165
      if (input_stream_rewind(s) < 0) {
166
        fprintf(stderr, "AVPacket read failed: %d!!!\n", res);
167
        *size = -1;
169
      if (s->loop) {
170
        if (input_stream_rewind(s) >= 0) {
171
          *size = 0;
172
          *ts = s->last_ts;
168 173

  
169
        return NULL;
174
          return NULL;
175
        }
170 176
      }
171
      *size = 0;
172
      *ts = s->last_ts;
177
      fprintf(stderr, "AVPacket read failed: %d!!!\n", res);
178
      *size = -1;
173 179

  
174 180
      return NULL;
175 181
    }

Also available in: Unified diff