~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/session/phone/videoframe.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * libjingle
3
 
 * Copyright 2004 Google Inc.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 *
8
 
 *  1. Redistributions of source code must retain the above copyright notice,
9
 
 *     this list of conditions and the following disclaimer.
10
 
 *  2. Redistributions in binary form must reproduce the above copyright notice,
11
 
 *     this list of conditions and the following disclaimer in the documentation
12
 
 *     and/or other materials provided with the distribution.
13
 
 *  3. The name of the author may not be used to endorse or promote products
14
 
 *     derived from this software without specific prior written permission.
15
 
 *
16
 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
 
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 
 */
27
 
 
28
 
#ifndef TALK_SESSION_PHONE_VIDEOFRAME_H_
29
 
#define TALK_SESSION_PHONE_VIDEOFRAME_H_
30
 
 
31
 
#include "talk/base/basictypes.h"
32
 
 
33
 
namespace flute {
34
 
class MagicCamVideoRenderer;
35
 
}
36
 
 
37
 
namespace cricket {
38
 
 
39
 
// Simple rotation constants.
40
 
enum {
41
 
  ROTATION_0 = 0,
42
 
  ROTATION_90 = 90,
43
 
  ROTATION_180 = 180,
44
 
  ROTATION_270 = 270
45
 
};
46
 
 
47
 
// Represents a YUV420 (a.k.a. I420) video frame.
48
 
class VideoFrame {
49
 
  friend class flute::MagicCamVideoRenderer;
50
 
 
51
 
 public:
52
 
  VideoFrame() : rendered_(false) {}
53
 
  virtual ~VideoFrame() {}
54
 
 
55
 
  // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|.
56
 
  // |h| can be negative indicating a vertically flipped image.
57
 
  // |dw| is destination width; can be less than |w| if cropping is desired.
58
 
  // |dh| is destination height, like |dw|, but must be a positive number.
59
 
  // Returns whether the function succeeded or failed.
60
 
  virtual bool Reset(uint32 fourcc, int w, int h, int dw, int dh,
61
 
                     uint8 *sample, size_t sample_size,
62
 
                     size_t pixel_width, size_t pixel_height,
63
 
                     int64 elapsed_time, int64 time_stamp, int rotation) = 0;
64
 
 
65
 
  // Basic accessors.
66
 
  virtual size_t GetWidth() const = 0;
67
 
  virtual size_t GetHeight() const = 0;
68
 
  size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; }
69
 
  size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; }
70
 
  size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); }
71
 
  virtual const uint8 *GetYPlane() const = 0;
72
 
  virtual const uint8 *GetUPlane() const = 0;
73
 
  virtual const uint8 *GetVPlane() const = 0;
74
 
  virtual uint8 *GetYPlane() = 0;
75
 
  virtual uint8 *GetUPlane() = 0;
76
 
  virtual uint8 *GetVPlane() = 0;
77
 
  virtual int32 GetYPitch() const = 0;
78
 
  virtual int32 GetUPitch() const = 0;
79
 
  virtual int32 GetVPitch() const = 0;
80
 
 
81
 
  // For retrieving the aspect ratio of each pixel. Usually this is 1x1, but
82
 
  // the aspect_ratio_idc parameter of H.264 can specify non-square pixels.
83
 
  virtual size_t GetPixelWidth() const = 0;
84
 
  virtual size_t GetPixelHeight() const = 0;
85
 
 
86
 
  virtual int64 GetElapsedTime() const = 0;
87
 
  virtual int64 GetTimeStamp() const = 0;
88
 
  virtual void SetElapsedTime(int64 elapsed_time) = 0;
89
 
  virtual void SetTimeStamp(int64 time_stamp) = 0;
90
 
 
91
 
  // Indicates the rotation angle in degrees.
92
 
  virtual int GetRotation() const = 0;
93
 
 
94
 
  // Make a shallow copy of the frame. The frame buffer itself is not copied.
95
 
  // Both the current and new VideoFrame will share a single reference-counted
96
 
  // frame buffer.
97
 
  virtual VideoFrame *Copy() const = 0;
98
 
 
99
 
  // Since VideoFrame supports shallow copy and the internal frame buffer might
100
 
  // be shared, in case VideoFrame needs exclusive access of the frame buffer,
101
 
  // user can call MakeExclusive() to make sure the frame buffer is exclusive
102
 
  // accessable to the current object.  This might mean a deep copy of the frame
103
 
  // buffer if it is currently shared by other objects.
104
 
  virtual bool MakeExclusive() = 0;
105
 
 
106
 
  // Writes the frame into the given frame buffer, provided that it is of
107
 
  // sufficient size. Returns the frame's actual size, regardless of whether
108
 
  // it was written or not (like snprintf). If there is insufficient space,
109
 
  // nothing is written.
110
 
  virtual size_t CopyToBuffer(uint8 *buffer, size_t size) const = 0;
111
 
 
112
 
  // Converts the I420 data to RGB of a certain type such as ARGB and ABGR.
113
 
  // Returns the frame's actual size, regardless of whether it was written or
114
 
  // not (like snprintf). Parameters size and stride_rgb are in units of bytes.
115
 
  // If there is insufficient space, nothing is written.
116
 
  virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8 *buffer,
117
 
                                    size_t size, int stride_rgb) const = 0;
118
 
 
119
 
  // Writes the frame into the given planes, stretched to the given width and
120
 
  // height. The parameter "interpolate" controls whether to interpolate or just
121
 
  // take the nearest-point. The parameter "crop" controls whether to crop this
122
 
  // frame to the aspect ratio of the given dimensions before stretching.
123
 
  virtual void StretchToPlanes(uint8 *y, uint8 *u, uint8 *v,
124
 
                               int32 pitchY, int32 pitchU, int32 pitchV,
125
 
                               size_t width, size_t height,
126
 
                               bool interpolate, bool crop) const;
127
 
 
128
 
  // Writes the frame into the given frame buffer, stretched to the given width
129
 
  // and height, provided that it is of sufficient size. Returns the frame's
130
 
  // actual size, regardless of whether it was written or not (like snprintf).
131
 
  // If there is insufficient space, nothing is written. The parameter
132
 
  // "interpolate" controls whether to interpolate or just take the
133
 
  // nearest-point. The parameter "crop" controls whether to crop this frame to
134
 
  // the aspect ratio of the given dimensions before stretching.
135
 
  virtual size_t StretchToBuffer(size_t w, size_t h, uint8 *buffer, size_t size,
136
 
                                 bool interpolate, bool crop) const;
137
 
 
138
 
  // Writes the frame into the target VideoFrame, stretched to the size of that
139
 
  // frame. The parameter "interpolate" controls whether to interpolate or just
140
 
  // take the nearest-point. The parameter "crop" controls whether to crop this
141
 
  // frame to the aspect ratio of the target frame before stretching.
142
 
  virtual void StretchToFrame(VideoFrame *target, bool interpolate,
143
 
                              bool crop) const;
144
 
 
145
 
  // Stretches the frame to the given size, creating a new VideoFrame object to
146
 
  // hold it. The parameter "interpolate" controls whether to interpolate or
147
 
  // just take the nearest-point. The parameter "crop" controls whether to crop
148
 
  // this frame to the aspect ratio of the given dimensions before stretching.
149
 
  virtual VideoFrame *Stretch(size_t w, size_t h, bool interpolate,
150
 
                              bool crop) const;
151
 
 
152
 
  // Sets the video frame to black.
153
 
  bool SetToBlack();
154
 
 
155
 
  // Tests if sample is valid.  Returns true if valid.
156
 
  static bool Validate(uint32 fourcc, int w, int h,
157
 
                       const uint8 *sample, size_t sample_size);
158
 
 
159
 
  // Size of an I420 image of given dimensions when stored as a frame buffer.
160
 
  static size_t SizeOf(size_t w, size_t h) {
161
 
    return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
162
 
  }
163
 
 
164
 
 protected:
165
 
  // Creates an empty frame.
166
 
  virtual VideoFrame* CreateEmptyFrame(int w, int h,
167
 
                                       size_t pixel_width, size_t pixel_height,
168
 
                                       int64 elapsed_time,
169
 
                                       int64 time_stamp) const = 0;
170
 
 
171
 
  // The frame needs to be rendered to magiccam only once.
172
 
  // TODO: Remove this flag once magiccam rendering is fully replaced
173
 
  // by client3d rendering.
174
 
  mutable bool rendered_;
175
 
};
176
 
 
177
 
}  // namespace cricket
178
 
 
179
 
#endif  // TALK_SESSION_PHONE_VIDEOFRAME_H_