00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "NvUtils.h"
00030 #include "NvBuffer.h"
00031 #include "NvLogging.h"
00032 #include <fstream>
00033
00034 int
00035 read_video_frame(std::ifstream * stream, NvBuffer & buffer)
00036 {
00037 uint32_t i, j;
00038 char *data;
00039
00040 for (i = 0; i < buffer.n_planes; i++)
00041 {
00042 NvBuffer::NvBufferPlane &plane = buffer.planes[i];
00043 std::streamsize bytes_to_read =
00044 plane.fmt.bytesperpixel * plane.fmt.width;
00045 data = (char *) plane.data;
00046 plane.bytesused = 0;
00047 for (j = 0; j < plane.fmt.height; j++)
00048 {
00049 stream->read(data, bytes_to_read);
00050 if (stream->gcount() < bytes_to_read)
00051 return -1;
00052 data += plane.fmt.stride;
00053 }
00054 plane.bytesused = plane.fmt.stride * plane.fmt.height;
00055 }
00056 return 0;
00057 }
00058
00059 int
00060 write_video_frame(std::ofstream * stream, NvBuffer &buffer)
00061 {
00062 uint32_t i, j;
00063 char *data;
00064
00065 for (i = 0; i < buffer.n_planes; i++)
00066 {
00067 NvBuffer::NvBufferPlane &plane = buffer.planes[i];
00068 size_t bytes_to_write =
00069 plane.fmt.bytesperpixel * plane.fmt.width;
00070
00071 data = (char *) plane.data;
00072 for (j = 0; j < plane.fmt.height; j++)
00073 {
00074 stream->write(data, bytes_to_write);
00075 if (!stream->good())
00076 return -1;
00077 data += plane.fmt.stride;
00078 }
00079 }
00080 return 0;
00081 }