1 // ***************************************************************** -*- C++ -*-
2 /*
3  * Copyright (C) 2004-2017 Andreas Huggel <ahuggel@gmx.net>
4  *
5  * This program is part of the Exiv2 distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program 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 this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
20  */
21 /*!
22   @file    asfvideo.hpp
23   @brief   An Image subclass to support ASF video files
24   @version $Rev$
25   @author  Abhinav Badola for GSoC 2012
26            <a href="mailto:mail.abu.to@gmail.com">mail.abu.to@gmail.com</a>
27   @date    08-Aug-12, AB: created
28  */
29 #ifndef ASFVIDEO_HPP
30 #define ASFVIDEO_HPP
31 
32 // *****************************************************************************
33 // included header files
34 #include "exif.hpp"
35 #include "image.hpp"
36 #include "tags_int.hpp"
37 
38 // *****************************************************************************
39 // namespace extensions
40 using namespace Exiv2::Internal;
41 
42 namespace Exiv2 {
43 
44 // *****************************************************************************
45 // class definitions
46 
47     // Add ASF to the supported image formats
48     namespace ImageType {
49         const int asf = 24; //!< Treating asf as an image type>
50     }
51 
52     /*!
53       @brief Class to access ASF video files.
54      */
55     class EXIV2API AsfVideo:public Image
56     {
57     public:
58         //! @name Creators
59         //@{
60         /*!
61           @brief Constructor for a ASF video. Since the constructor
62               can not return a result, callers should check the good() method
63               after object construction to determine success or failure.
64           @param io An auto-pointer that owns a BasicIo instance used for
65               reading and writing image metadata. \b Important: The constructor
66               takes ownership of the passed in BasicIo instance through the
67               auto-pointer. Callers should not continue to use the BasicIo
68               instance after it is passed to this method. Use the Image::io()
69               method to get a temporary reference.
70          */
71         AsfVideo(BasicIo::AutoPtr io);
72         //@}
73 
74         //! @name Manipulators
75         //@{
76         void readMetadata();
77         void writeMetadata();
78         //@}
79 
80         //! @name Accessors
81         //@{
82         std::string mimeType() const;
83         //@}
84 
85     protected:
86         /*!
87           @brief Check for a valid tag and decode the block at the current IO
88           position. Calls tagDecoder() or skips to next tag, if required.
89          */
90         void decodeBlock();
91         /*!
92           @brief Interpret tag information, and call the respective function
93               to save it in the respective XMP container. Decodes a Tag
94               Information and saves it in the respective XMP container, if
95               the block size is small.
96           @param tv Pointer to current tag,
97           @param size Size of the data block used to store Tag Information.
98          */
99         void tagDecoder(const TagVocabulary* tv, uint64_t size);
100         /*!
101           @brief Interpret File_Properties tag information, and save it in
102               the respective XMP container.
103          */
104         void fileProperties();
105         /*!
106           @brief Interpret Stream_Properties tag information, and save it
107               in the respective XMP container.
108          */
109         void streamProperties();
110         /*!
111           @brief Interpret Codec_List tag information, and save it in
112               the respective XMP container.
113          */
114         void codecList();
115         /*!
116           @brief Interpret Content_Description tag information, and save it
117               in the respective XMP container.
118           @param size Size of the data block used to store Tag Data.
119          */
120         void contentDescription(uint64_t size);
121         /*!
122           @brief Interpret Extended_Stream_Properties tag information, and
123               save it in the respective XMP container.
124           @param size Size of the data block used to store Tag Data.
125          */
126         void extendedStreamProperties(uint64_t size);
127         /*!
128           @brief Interpret Header_Extension tag information, and save it in
129               the respective XMP container.
130           @param size Size of the data block used to store Tag Data.
131          */
132         void headerExtension(uint64_t size);
133         /*!
134           @brief Interpret Metadata, Extended_Content_Description,
135               Metadata_Library tag information, and save it in the respective
136               XMP container.
137           @param meta A default integer which helps to overload the function
138               for various Tags that have a similar method of decoding.
139          */
140         void metadataHandler(int meta = 1);
141         /*!
142           @brief Calculates Aspect Ratio of a video, and stores it in the
143               respective XMP container.
144          */
145         void aspectRatio();
146 
147     private:
148         //! @name NOT Implemented
149         //@{
150         //! Copy constructor
151         AsfVideo(const AsfVideo& rhs);
152         //! Assignment operator
153         AsfVideo& operator=(const AsfVideo& rhs);
154         //@}
155 
156     private:
157         //! Variable to check the end of metadata traversing.
158         bool continueTraversing_;
159         //! Variable which stores current position of the read pointer.
160         uint64_t localPosition_;
161         //! Variable which stores current stream being processsed.
162         int streamNumber_;
163         //! Variable to store height and width of a video frame.
164         uint64_t height_, width_;
165 
166     }; //Class AsfVideo
167 
168 // *****************************************************************************
169 // template, inline and free functions
170 
171     // These could be static private functions on Image subclasses but then
172     // ImageFactory needs to be made a friend.
173     /*!
174       @brief Create a new AsfVideo instance and return an auto-pointer to it.
175           Caller owns the returned object and the auto-pointer ensures that
176           it will be deleted.
177      */
178     EXIV2API Image::AutoPtr newAsfInstance(BasicIo::AutoPtr io, bool create);
179 
180     //! Check if the file iIo is a Windows Asf Video.
181     EXIV2API bool isAsfType(BasicIo& iIo, bool advance);
182 
183 }                                       // namespace Exiv2
184 
185 #endif                                  // #ifndef ASFVIDEO_HPP_
186