~ubuntu-branches/ubuntu/feisty/avidemux/feisty

« back to all changes in this revision

Viewing changes to avidemux/ADM_matroska/ADM_mkv_audio.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-12-15 17:13:20 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215171320-w79pvpehxx2fr217
Tags: 1:2.3.0-0.0ubuntu1
* Merge from debian-multimedia.org, remaining Ubuntu change:
  - desktop file,
  - no support for ccache and make -j.
* Closes Ubuntu: #69614.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    copyright            : (C) 2006 by mean
 
3
    email                : fixounet@free.fr
 
4
 ***************************************************************************/
 
5
 
 
6
/***************************************************************************
 
7
 *                                                                         *
 
8
 *   This program is free software; you can redistribute it and/or modify  *
 
9
 *   it under the terms of the GNU General Public License as published by  *
 
10
 *   the Free Software Foundation; either version 2 of the License, or     *
 
11
 *   (at your option) any later version.                                   *
 
12
 *                                                                         *
 
13
 ***************************************************************************/
 
14
#include "config.h"
 
15
 
 
16
#include <stdio.h>
 
17
#include <stdlib.h>
 
18
 
 
19
#include <string.h>
 
20
 
 
21
#include "math.h"
 
22
 
 
23
#include "ADM_library/default.h"
 
24
#include "ADM_editor/ADM_Video.h"
 
25
#include <ADM_assert.h>
 
26
 
 
27
#include "ADM_library/fourcc.h"
 
28
#include "ADM_toolkit/toolkit.hxx"
 
29
 
 
30
#include "ADM_mkv.h"
 
31
 
 
32
extern "C"
 
33
{
 
34
#include "ADM_lavcodec/avcodec.h"
 
35
#include "ADM_lavformat/avformat.h"
 
36
};
 
37
 
 
38
#define CONTEXT ((AVFormatContext* )_context)
 
39
 
 
40
/*
 
41
    __________________________________________________________
 
42
*/
 
43
 
 
44
mkvAudio::~mkvAudio()
 
45
{
 
46
  printf("[MkvAudio] Destroying track\n");
 
47
  if(_context)
 
48
  {
 
49
    av_close_input_file(CONTEXT);
 
50
    _context=NULL;
 
51
  }
 
52
}
 
53
/*
 
54
    __________________________________________________________
 
55
*/
 
56
 
 
57
mkvAudio::mkvAudio(char *name,mkvAudioTrak *track)
 
58
{
 
59
   printf("[MkvAudio] Creating track\n");
 
60
   _trackIndex=track->streamIndex; 
 
61
   _wavheader=&(track->wavHeader);
 
62
  _extraDataLen=track->extraDataLen;
 
63
  _extraData=track->extraData;
 
64
  _length=track->length;
 
65
  
 
66
  // Open it
 
67
  AVInputFormat *format;
 
68
  
 
69
  printf("[Matroska] Open\n");
 
70
  format= av_find_input_format("matroska");
 
71
  ADM_assert(format)
 
72
  ADM_assert(0<= av_open_input_file((AVFormatContext **)&_context, name, format, 0, NULL));
 
73
  av_find_stream_info(CONTEXT);
 
74
}
 
75
/*
 
76
    __________________________________________________________
 
77
*/
 
78
 
 
79
uint32_t            mkvAudio::read(uint32_t len,uint8_t *buffer)
 
80
{
 
81
  uint32_t lan,samples;
 
82
  if(!getPacket(      buffer,    &lan, &samples)) return 0;
 
83
  return lan;
 
84
}
 
85
/*
 
86
    __________________________________________________________
 
87
*/
 
88
 
 
89
uint8_t   mkvAudio::goTo(uint32_t newoffset)
 
90
{
 
91
  return 1; 
 
92
}
 
93
/*
 
94
    __________________________________________________________
 
95
*/
 
96
 
 
97
uint8_t   mkvAudio::goToTime(uint32_t newoffset)
 
98
{
 
99
  return 1; 
 
100
}
 
101
/*
 
102
    __________________________________________________________
 
103
*/
 
104
 
 
105
uint8_t   mkvAudio::extraData(uint32_t *l,uint8_t **d)
 
106
{
 
107
  if(_extraDataLen)
 
108
  {
 
109
    *l=_extraDataLen;
 
110
    *d=_extraData;  
 
111
  }
 
112
  else
 
113
  {
 
114
    *l=0;
 
115
    *d=NULL; 
 
116
  }
 
117
  return 1;
 
118
}
 
119
/*
 
120
    __________________________________________________________
 
121
*/
 
122
 
 
123
uint8_t  mkvAudio::getPacket(uint8_t *dest, uint32_t *len, uint32_t *samples)
 
124
{
 
125
  
 
126
  AVPacket pkt1, *pkt = &pkt1;
 
127
  int ret;
 
128
  while(1)
 
129
  {
 
130
    ret = av_read_frame(CONTEXT, pkt);
 
131
    if (ret < 0) 
 
132
    {
 
133
      printf("[MKV] Error reading audio frame %d\n");
 
134
      return 0;
 
135
    }
 
136
    if(pkt->stream_index!=_trackIndex) 
 
137
    {
 
138
      //printf("[MKV] Wrong stream %u %u\n",pkt->stream_index,_videoIndex);
 
139
      continue;
 
140
    }
 
141
    memcpy(dest,pkt->data,pkt->size);
 
142
    *len=pkt->size;
 
143
    *samples=1024; // FIXME
 
144
    break;
 
145
  }
 
146
  return 1; 
 
147
}
 
148
//EOF