summaryrefslogtreecommitdiff
path: root/src/multiplexer.h
blob: 8d67766bacf208698538596f91d8f6652341ab6b (plain)
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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
 *            multiplexer.h
 *
 *  Wed Aug 31 13:05:18 CEST 2005
 *  Copyright  2005 Bent Bisballe Nyeng
 *  deva@aasimon.org
 ****************************************************************************/

/*
 *  This file is part of MIaV.
 *
 *  MIaV is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  MIaV is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with MIaV; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
#include "config.h"
#ifndef __MIAV_MULTIPLEXER_H__
#define __MIAV_MULTIPLEXER_H__

#include "iso11172-1.h"
#include "iso11172-2.h"
#include "iso11172-3.h"

#include "file.h"
#include "info.h"
#include "frame.h"

/**
 * Multiplexer configuration
 */
// How many packets should we put in one pack
#define PACKETS_PER_PACK 3

// How many packets bewteen audio packs
#define AUDIO_PACKET_FREQUENCY 10

// How many packs bewteen system headers
#define SYSTEM_HEADER_FREQUENCY 5

// Size of video or audio data pr. packet
#define PACKET_SIZE 2028

/**
 * Other stuff
 */
// The number of streamtypes.
#define NUM_TYPES 2

// Enum of the streamtypes.
typedef enum {
  TYPE_VIDEO,
  TYPE_AUDIO
} StreamType;


class Multiplexer {
public:
  Multiplexer(File *file, Info *info, volatile bool *running,
              FramePriorityQueue *v_q, pthread_mutex_t *v_m, sem_t *v_s, 
              FramePriorityQueue *a_q, pthread_mutex_t *a_m, sem_t *a_s);
  ~Multiplexer();

  void multiplex();

private:
  unsigned long long int SCR;

  double written[NUM_TYPES];

  void iso11172_stream();
  bool pack();
  void system_header();
  bool packet();
  bool packet(StreamType type);
  /*
  void audio_packet();
  void video_packet();

  void audio_data(ISO11172_3::header *header);
  void audio_data_layer_I(ISO11172_3::header *header);
  void audio_data_layer_II(ISO11172_3::header *header);
  void audio_data_layer_III(ISO11172_3::header *header);

  void video_data(ISO11172_2::sequence_header_1 *header1,
                  ISO11172_2::sequence_header_2 *header2);
  */
  // Frequency variables
  unsigned int write_system_header;
  unsigned int write_audio_packet;

  Frame *getFrame(StreamType type);
  int read_stream(char *buf, unsigned int size, StreamType type);

  FramePriorityQueue *queue[NUM_TYPES];
  pthread_mutex_t *mutex[NUM_TYPES];
  sem_t *sem[NUM_TYPES];

  Frame *frame[NUM_TYPES];
  unsigned int frame_number[NUM_TYPES];
  unsigned int read[NUM_TYPES];

  File *file;
  Info *info;
  volatile bool *running;

  // Audio Header
 bool audio_header_read;
};

#endif/*__MIAV_MULTIPLEXER_H__*/