OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [test/] [decoder/] [ldecod/] [src/] [nal.c] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jamey.hick
 
2
/*!
3
 ************************************************************************
4
 * \file  nal.c
5
 *
6
 * \brief
7
 *    Converts Encapsulated Byte Sequence Packets (EBSP) to Raw Byte
8
 *    Sequence Packets (RBSP), and then onto String Of Data Bits (SODB)
9
 *
10
 * \author
11
 *    Main contributors (see contributors.h for copyright, address and affiliation details)
12
 *    - Shankar L. Regunathan <shanre@microsoft.com>
13
 ************************************************************************
14
 */
15
 
16
#include "contributors.h"
17
 
18
#include <assert.h>
19
#include <stdlib.h>
20
#include <math.h>
21
#include <string.h>
22
 
23
#include "defines.h"
24
#include "global.h"
25
 
26
 
27
 /*!
28
 ************************************************************************
29
 * \brief
30
 *    Converts RBSP to string of data bits
31
 * \param streamBuffer
32
 *          pointer to buffer containing data
33
 *  \param last_byte_pos
34
 *          position of the last byte containing data.
35
 * \return last_byte_pos
36
 *          position of the last byte pos. If the last-byte was entirely a stuffing byte,
37
 *          it is removed, and the last_byte_pos is updated.
38
 *
39
************************************************************************/
40
 
41
int RBSPtoSODB(byte *streamBuffer, int last_byte_pos)
42
{
43
  int ctr_bit, bitoffset;
44
 
45
  bitoffset = 0;
46
  //find trailing 1
47
  ctr_bit = (streamBuffer[last_byte_pos-1] & (0x01<<bitoffset));   // set up control bit
48
 
49
  while (ctr_bit==0)
50
  {                 // find trailing 1 bit
51
    bitoffset++;
52
    if(bitoffset == 8)
53
    {
54
      if(last_byte_pos == 0)
55
        printf(" Panic: All zero data sequence in RBSP \n");
56
      assert(last_byte_pos != 0);
57
      last_byte_pos -= 1;
58
      bitoffset = 0;
59
    }
60
    ctr_bit= streamBuffer[last_byte_pos-1] & (0x01<<(bitoffset));
61
  }
62
 
63
 
64
  // We keep the stop bit for now
65
/*  if (remove_stop)
66
  {
67
    streamBuffer[last_byte_pos-1] -= (0x01<<(bitoffset));
68
    if(bitoffset == 7)
69
      return(last_byte_pos-1);
70
    else
71
      return(last_byte_pos);
72
  }
73
*/
74
  return(last_byte_pos);
75
 
76
}
77
 
78
 
79
/*!
80
************************************************************************
81
* \brief
82
*    Converts Encapsulated Byte Sequence Packets to RBSP
83
* \param streamBuffer
84
*    pointer to data stream
85
* \param end_bytepos
86
*    size of data stream
87
* \param begin_bytepos
88
*    Position after beginning
89
************************************************************************/
90
 
91
 
92
int EBSPtoRBSP(byte *streamBuffer, int end_bytepos, int begin_bytepos)
93
{
94
  int i, j, count;
95
  count = 0;
96
 
97
  if(end_bytepos < begin_bytepos)
98
    return end_bytepos;
99
 
100
  j = begin_bytepos;
101
 
102
  for(i = begin_bytepos; i < end_bytepos; i++)
103
  { //starting from begin_bytepos to avoid header information
104
    if(count == ZEROBYTES_SHORTSTARTCODE && streamBuffer[i] == 0x03)
105
    {
106
      i++;
107
      count = 0;
108
    }
109
    streamBuffer[j] = streamBuffer[i];
110
    if(streamBuffer[i] == 0x00)
111
      count++;
112
    else
113
      count = 0;
114
    j++;
115
  }
116
 
117
  return j;
118
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.