Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BitstreamParser.cpp « LAVAudio « decoder - github.com/mpc-hc/LAVFilters.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0ba59629872bf28ee19dd42d7f781fa596d35f8 (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
/*
 *      Copyright (C) 2010-2015 Hendrik Leppkes
 *      http://www.1f0.de
 *
 *  This program 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.
 *
 *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "stdafx.h"
#include "BitstreamParser.h"

#include "libavcodec/aac_ac3_parser.h"

#include "parser/dts.h"


CBitstreamParser::CBitstreamParser()
{
  init_dts_parser((DTSParserContext **)&m_pParserContext);
  Reset();
}

CBitstreamParser::~CBitstreamParser()
{
  close_dts_parser((DTSParserContext **)&m_pParserContext);
}

void CBitstreamParser::Reset()
{
  m_dwBlocks     = 0;
  m_dwFrameSize  = 0;
  m_dwSampleRate = 0;
  m_dwSamples    = 0;
  m_bDTSHD       = FALSE;
  memset(&m_DTSHeader, 0, sizeof(m_DTSHeader));
}


HRESULT CBitstreamParser::Parse(AVCodecID codec, BYTE *pBuffer, DWORD dwSize, void *pParserContext)
{
  switch (codec) {
  case AV_CODEC_ID_DTS:
    return ParseDTS(pBuffer, dwSize);
  case AV_CODEC_ID_AC3:
  case AV_CODEC_ID_EAC3:
    return ParseAC3(pBuffer, dwSize, pParserContext);
  }
  return S_OK;
}

HRESULT CBitstreamParser::ParseDTS(BYTE *pBuffer, DWORD dwSize)
{
  int ret = parse_dts_header((DTSParserContext *)m_pParserContext, &m_DTSHeader, pBuffer, (unsigned)dwSize);
  if (ret < 0)
    return E_FAIL;

  m_bDTSHD = m_bDTSHD || m_DTSHeader.IsHD;

  m_dwBlocks      = m_DTSHeader.Blocks;
  m_dwSampleRate  = m_DTSHeader.SampleRate;
  m_dwFrameSize   = m_DTSHeader.FrameSize;
  m_dwSamples     = m_DTSHeader.SamplesPerBlock * m_dwBlocks;

  return S_OK;
}

HRESULT CBitstreamParser::ParseAC3(BYTE *pBuffer, DWORD dwSize, void *pParserContext)
{
  AACAC3ParseContext *ctx = (AACAC3ParseContext *)pParserContext;

  m_dwSampleRate = ctx->sample_rate;

  // E-AC3 always combines 6 blocks, resulting in 1536 samples
  m_dwSamples    = (ctx->codec_id == AV_CODEC_ID_EAC3) ? (6 * 256) : ctx->samples;

  return S_OK;
}