AVPKit
IVideoPicture.cpp
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #include <com/avpkit/ferry/Logger.h>
21 
22 #include "IVideoPicture.h"
23 #include "Global.h"
24 #include "VideoPicture.h"
25 #include <stdexcept>
26 
27 VS_LOG_SETUP(VS_CPP_PACKAGE);
28 
29 namespace com { namespace avpkit { namespace core
30 {
31 
32  IVideoPicture :: IVideoPicture()
33  {
34  }
35 
36  IVideoPicture :: ~IVideoPicture()
37  {
38  }
39 
40  IVideoPicture*
41  IVideoPicture :: make(IPixelFormat::Type format, int width, int height)
42  {
43  Global::init();
44  return VideoPicture::make(format, width, height);
45  }
46 
50  IPixelFormat::Type format, int width, int height)
51  {
52  Global::init();
53  return VideoPicture::make(buffer, format, width, height);
54  }
55 
56 
59  {
60  IVideoPicture* retval = 0;
61  Global::init();
62  try
63  {
64  if (!srcFrame)
65  throw std::runtime_error("no source data to copy");
66 
67  retval = IVideoPicture::make(srcFrame->getPixelType(), srcFrame->getWidth(), srcFrame->getHeight());
68  if (!retval)
69  throw std::runtime_error("could not allocate new frame");
70 
71  if (!retval->copy(srcFrame))
72  throw std::runtime_error("could not copy source frame");
73  }
74  catch (std::bad_alloc &e)
75  {
76  VS_REF_RELEASE(retval);
77  throw e;
78  }
79  catch (std::exception & e)
80  {
81  VS_LOG_DEBUG("got error: %s", e.what());
82  VS_REF_RELEASE(retval);
83  }
84  return retval;
85  }
86 }}}
static void init()
Internal Only.
Definition: Global.cpp:157
Represents one raw (undecoded) picture in a video stream, plus a timestamp for when to display that v...
Definition: IVideoPicture.h:40
virtual int getWidth()=0
What is the width of the picture.
static IVideoPicture * make(IPixelFormat::Type format, int width, int height)
Get a new picture object.
virtual int getHeight()=0
What is the height of the picture.
virtual bool copy(IVideoPicture *srcPicture)=0
Copy the contents of the given picture into this picture.
virtual IPixelFormat::Type getPixelType()=0
Returns the pixel format of the picture.
static VideoPicture * make(IPixelFormat::Type format, int width, int height)
The default factory for a frame.
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...