~josejuan-sanchez/esajpip/emptypackets

« back to all changes in this revision

Viewing changes to src/jpip/databin_server.h

  • Committer: José Juan Sánchez Hernández
  • Date: 2012-07-18 11:40:37 UTC
  • Revision ID: josejuan.sanchez@gmail.com-20120718114037-mslgs1evd0gwjp2y
Modifications to control empty packets

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include "jpeg2000/range.h"
17
17
#include "jpeg2000/image_index.h"
18
18
 
19
 
 
20
19
namespace jpip
21
20
{
22
21
 
54
53
    ImageIndex::Ptr im_index;   ///< Pointer to the associated image index
55
54
    DataBinWriter data_writer;  ///< Data-bin writer for generating the chunks
56
55
 
 
56
    // PRUEBA
 
57
    vector<Packet> packets_sent;
 
58
    vector<FileSegment> list_of_empty_segments;
 
59
    // ****
 
60
 
57
61
    enum {
58
62
      MINIMUM_SPACE = 60                ///< Minimum space in the chunk
59
63
    };
108
112
 
109
113
      return res;
110
114
    }
111
 
                
 
115
 
 
116
    // PRUEBA
 
117
    // ****
 
118
    template<int BIN_CLASS> int WriteSegment2(int num_codestream, int id, vector<FileSegment> segments, int offset = 0, bool last = true)
 
119
    {
 
120
      int cached = cache_model.GetDataBin<BIN_CLASS>(num_codestream, id);
 
121
      int res = 1, seg_cached = cached - offset;
 
122
 
 
123
      // Calculamos la suma de todos los segmentos del vector
 
124
      uint64_t length = 0;
 
125
      for(int i=0; i < segments.size(); i++)
 
126
      {
 
127
        length = length + segments.at(i).length;
 
128
      }
 
129
      // ****
 
130
 
 
131
      if((cached != INT_MAX) && (((int)length - seg_cached) >= 0)) {
 
132
        int free = data_writer.GetFree() - MINIMUM_SPACE;
 
133
 
 
134
        if(free <= 0) {
 
135
          eof = true;
 
136
          res = 0;
 
137
 
 
138
        } else {
 
139
 
 
140
          // TODO
 
141
          // segment.RemoveFirst(seg_cached);
 
142
          //
 
143
 
 
144
          if((int)length > free) {
 
145
            length = free;
 
146
            last = false;
 
147
            res = 0;
 
148
          }
 
149
 
 
150
          data_writer.SetCodestream(num_codestream);
 
151
          data_writer.SetDataBinClass(BIN_CLASS);
 
152
 
 
153
          File::Ptr file_ptr;
 
154
          if(BIN_CLASS == DataBinClass::META_DATA) file_ptr = file;
 
155
          else {
 
156
                  int idx = range.GetIndex(num_codestream);
 
157
                  if((int)files.size() <= idx) return -1;
 
158
                  file_ptr = files[idx];
 
159
          }
 
160
 
 
161
          if(!data_writer.Write2(id, cached, *file_ptr, segments, last)) res = -1;
 
162
          else cache_model.AddToDataBin<BIN_CLASS>(num_codestream, id, length, last);
 
163
        }
 
164
      }
 
165
 
 
166
      return res;
 
167
    }
 
168
 
 
169
 
112
170
    /**
113
171
     * Writes a new place-holder segment, only if it is possible to write it completely.
114
172
     * @param num_codestream Index number of the codestream.
147
205
 
148
206
  public:
149
207
    /**
150
 
     * Initializes the obect.
 
208
     * Initializes the object.
151
209
     */
152
210
    DataBinServer()
153
211
    {