1 /***************************************************************************
2                           ADM_Video.cpp  -  description
3                              -------------------
4     begin                : Fri Apr 19 2002
5     copyright            : (C) 2002 by mean
6     email                : fixounet@free.fr
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 #include <math.h>
18 #include "ADM_default.h"
19 #include "ADM_Video.h"
~vidHeader()20 vidHeader::~vidHeader ()
21 {
22   if (_name)
23     delete[]_name;
24   _name = NULL;
25   if (_videoExtraLen)
26     {
27       delete[]_videoExtraData;
28       _videoExtraData = NULL;
29       _videoExtraLen = 0;
30     }
31   _name = NULL;
32 
33 }
34 
getExtraHeaderData(uint32_t * len,uint8_t ** data)35 uint8_t vidHeader::getExtraHeaderData (uint32_t * len, uint8_t ** data)
36 {
37   *len = _videoExtraLen;
38   if (*len)
39     {
40       *data = _videoExtraData;
41     }
42   else
43     *data = NULL;
44   return 1;
45 }
46 
vidHeader(void)47 vidHeader::vidHeader (void)
48 {
49   _name = NULL;
50   _videoExtraData = NULL;
51   _videoExtraLen = 0;
52   _isvideopresent = 0;
53   _isaudiopresent = 0;
54   memset(&_mainaviheader,0,sizeof(MainAVIHeader));
55   memset(&_videostream,0,sizeof(AVIStreamHeader));
56 }
57 
58 //_______________________________________
59 // Get simplified information for gui
60 //
61 //_____________________________________
getVideoInfo(aviInfo * info)62 uint8_t vidHeader::getVideoInfo (aviInfo * info)
63 {
64   double
65     u,
66     d;
67   if (!_isvideopresent)
68     return 0;
69 
70   info->width = _video_bih.biWidth;
71   info->height = _video_bih.biHeight;
72   info->nb_frames = _mainaviheader.dwTotalFrames;
73   info->fcc = _videostream.fccHandler;
74   info->bpp = _video_bih.biBitCount;
75   info->timebase_den = _videostream.dwRate;
76   info->timebase_num = _videostream.dwScale;
77   if (_mainaviheader.dwMicroSecPerFrame)
78   {
79     u = 1000*1000*1000;
80     d = _mainaviheader.dwMicroSecPerFrame;
81     info->fps1000 = (uint32_t) floor (u / d);
82     return 1;
83   }
84   u = _videostream.dwRate;
85   u *= 1000.F;
86   d = _videostream.dwScale;
87   if (_videostream.dwScale)
88     info->fps1000 = (uint32_t) floor (u / d);
89   else
90     info->fps1000 = 0;
91 
92 
93 
94   return 1;
95 }
96 
setMyName(const char * name)97 uint8_t vidHeader::setMyName (const char *name)
98 {
99   _name = new char[strlen (name) + 1];
100   ADM_assert (_name);
101   strcpy (_name, name);
102   return 1;
103 
104 }
105 
106 char *
getMyName(void)107 vidHeader::getMyName (void)
108 {
109   return _name;
110 }
111 
getFrameSize(uint32_t frame,uint32_t * size)112 uint8_t vidHeader::getFrameSize (uint32_t frame, uint32_t * size)
113 {
114   UNUSED_ARG (frame);
115   UNUSED_ARG (size);
116   return 0;
117 }
118 /**
119     \fn estimatePts
120     \brief Returns Pts of given frame or estimate if unknown
121 
122 */
estimatePts(uint32_t frame)123 uint64_t vidHeader::estimatePts(uint32_t frame)
124 {
125     uint64_t pts=getTime(frame);
126     if(pts!=ADM_NO_PTS) return pts; // The demuxer can provide the PTS
127     // Else guesstimate...
128     uint32_t count=0;
129     while(frame && getTime(frame)==ADM_NO_PTS)
130     {
131         count++;
132         frame--;
133     }
134     float f=_videostream.dwScale;
135     f*=1000*1000;
136     f/=_videostream.dwRate;
137     f*=count;
138     pts=getTime(frame)+count*(uint32_t)f;
139     return pts;
140 }
141 //
142