~ubuntu-branches/ubuntu/wily/libde265/wily

« back to all changes in this revision

Viewing changes to dec265/hdrcopy.cc

  • Committer: Package Import Robot
  • Author(s): Joachim Bauch
  • Date: 2015-07-16 11:07:46 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150716110746-76vsv24j3yux7tnu
Tags: 1.0.2-1
* Imported Upstream version 1.0.2
* Added new files to copyright information.
* Only export decoder API and update symbols for new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * H.265 video codec.
 
3
 * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
 
4
 *
 
5
 * This file is part of libde265.
 
6
 *
 
7
 * libde265 is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * libde265 is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with libde265.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
 
 
22
#include "libde265/nal-parser.h"
 
23
#include "libde265/decctx.h"
 
24
#include <assert.h>
 
25
 
 
26
error_queue errqueue;
 
27
 
 
28
video_parameter_set vps;
 
29
seq_parameter_set   sps;
 
30
pic_parameter_set   pps;
 
31
 
 
32
CABAC_encoder_bitstream writer;
 
33
 
 
34
 
 
35
void process_nal(NAL_unit* nal)
 
36
{
 
37
  de265_error err = DE265_OK;
 
38
 
 
39
  bitreader reader;
 
40
  bitreader_init(&reader, nal->data(), nal->size());
 
41
 
 
42
  nal_header nal_hdr;
 
43
  nal_hdr.read(&reader);
 
44
  writer.write_startcode();
 
45
  nal_hdr.write(writer);
 
46
 
 
47
  printf("NAL: 0x%x 0x%x -  unit type:%s temporal id:%d\n",
 
48
         nal->data()[0], nal->data()[1],
 
49
         get_NAL_name(nal_hdr.nal_unit_type),
 
50
         nal_hdr.nuh_temporal_id);
 
51
 
 
52
 
 
53
  if (nal_hdr.nal_unit_type<32) {
 
54
    //err = read_slice_NAL(reader, nal, nal_hdr);
 
55
  }
 
56
  else switch (nal_hdr.nal_unit_type) {
 
57
    case NAL_UNIT_VPS_NUT:
 
58
      vps.read(&errqueue, &reader);
 
59
      vps.dump(1);
 
60
      vps.write(&errqueue, writer);
 
61
      writer.flush_VLC();
 
62
      break;
 
63
 
 
64
    case NAL_UNIT_SPS_NUT:
 
65
      sps.read(&errqueue, &reader);
 
66
      sps.dump(1);
 
67
      sps.write(&errqueue, writer);
 
68
      writer.flush_VLC();
 
69
      break;
 
70
 
 
71
    case NAL_UNIT_PPS_NUT:
 
72
      //err = read_pps_NAL(reader);
 
73
      break;
 
74
 
 
75
    case NAL_UNIT_PREFIX_SEI_NUT:
 
76
    case NAL_UNIT_SUFFIX_SEI_NUT:
 
77
      //err = read_sei_NAL(reader, nal_hdr.nal_unit_type==NAL_UNIT_SUFFIX_SEI_NUT);
 
78
      break;
 
79
 
 
80
    case NAL_UNIT_EOS_NUT:
 
81
      //ctx->FirstAfterEndOfSequenceNAL = true;
 
82
      break;
 
83
    }
 
84
}
 
85
 
 
86
 
 
87
int main(int argc, char** argv)
 
88
{
 
89
  NAL_Parser nal_parser;
 
90
 
 
91
  FILE* fh = fopen(argv[1],"rb");
 
92
  unsigned char buf[1024];
 
93
 
 
94
  writer.write_bits(0,8); // because HM has an extra byte at the beginning
 
95
 
 
96
  while(!feof(fh))
 
97
    {
 
98
      int n = fread(buf,1,1024,fh);
 
99
      if (n>0) {
 
100
        nal_parser.push_data(buf,n, 0);
 
101
      }
 
102
 
 
103
      if (nal_parser.get_NAL_queue_length()>0) {
 
104
        NAL_unit* nal = nal_parser.pop_from_NAL_queue();
 
105
        assert(nal);
 
106
        process_nal(nal);
 
107
        nal_parser.free_NAL_unit(nal);
 
108
      }
 
109
    }
 
110
 
 
111
  fclose(fh);
 
112
 
 
113
  fh = fopen("out.bin","wb");
 
114
  fwrite(writer.data(), 1,writer.size(), fh);
 
115
  fclose(fh);
 
116
 
 
117
  return 0;
 
118
}