~ubuntu-branches/ubuntu/feisty/avidemux/feisty

« back to all changes in this revision

Viewing changes to avidemux/ADM_mplex/ADM_mplexin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2005-05-25 13:02:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050525130229-jw94cav0yhmg7vjw
Tags: 1:2.0.40-0.0
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: %{MODULE}
 
3
//
 
4
// Description:
 
5
//
 
6
//
 
7
// Author: %{AUTHOR} <%{EMAIL}>, (C) %{YEAR}
 
8
//
 
9
// Copyright: See COPYING file that comes with this distribution
 
10
//
 
11
//
 
12
#include "config.h"
 
13
 
 
14
#include <stdio.h>
 
15
#include <stdlib.h>
 
16
#include <math.h>
 
17
#include <string.h>
 
18
#include <sys/stat.h>
 
19
 
 
20
#include "interact.hpp"
 
21
 
 
22
#undef malloc
 
23
#undef realloc
 
24
#undef free
 
25
#include <ADM_assert.h>
 
26
 
 
27
#include "ADM_library/default.h"
 
28
#include "ADM_toolkit/toolkit.hxx"
 
29
 
 
30
 
 
31
#include "ADM_toolkit/ADM_debugID.h"
 
32
#define MODULE_NAME MODULE_LAVFORMAT
 
33
#include "ADM_toolkit/ADM_debug.h"
 
34
 
 
35
#include "cpu_accel.h"
 
36
#include "mjpeg_types.h"
 
37
#include "mjpeg_logging.h"
 
38
#include "mpegconsts.h"
 
39
 
 
40
#include "bits.hpp"
 
41
#include "outputstrm.hpp"
 
42
#include "multiplexor.hpp"
 
43
 
 
44
#include "ADM_inout.h"
 
45
 
 
46
FileOutputStream::FileOutputStream( const char *name_pat ) 
 
47
{
 
48
        strncpy( filename_pat, name_pat, MAXPATHLEN );
 
49
        snprintf( cur_filename, MAXPATHLEN, filename_pat, segment_num );
 
50
}
 
51
      
 
52
int FileOutputStream::Open()
 
53
{
 
54
        strm = fopen( cur_filename, "wb" );
 
55
        if( strm == NULL )
 
56
        {
 
57
                mjpeg_error_exit1( "Could not open for writing: %s", cur_filename );
 
58
        }
 
59
 
 
60
        return 0;
 
61
}
 
62
 
 
63
void FileOutputStream::Close()
 
64
 
65
    fclose(strm);
 
66
}
 
67
 
 
68
 
 
69
off_t
 
70
FileOutputStream::SegmentSize()
 
71
{
 
72
        struct stat stb;
 
73
    fstat(fileno(strm), &stb);
 
74
        off_t written = stb.st_size;
 
75
    return written;
 
76
}
 
77
 
 
78
void 
 
79
FileOutputStream::NextSegment( )
 
80
{
 
81
 
 
82
    
 
83
        fclose(strm);
 
84
        ++segment_num;
 
85
    
 
86
        cur_filename[strlen(cur_filename)-1]++; // increase
 
87
        strm = fopen( cur_filename, "wb" );
 
88
        if( strm == NULL )
 
89
        {
 
90
                mjpeg_error_exit1( "Could not open for writing: %s", cur_filename );
 
91
        }
 
92
 
 
93
        
 
94
}
 
95
 
 
96
void
 
97
FileOutputStream::Write( uint8_t *buf, unsigned int len )
 
98
{
 
99
    if( fwrite( buf, 1, len, strm ) != len )
 
100
    {
 
101
        mjpeg_error_exit1( "Failed write: %s", cur_filename );
 
102
    }
 
103
}
 
104