<div dir="ltr">Hi again,<div><br></div><div style>I can not solve problem. I want to mention my source code, so you may answer easily.</div><div style><br></div><div style>This is decoder init stream function.</div><div style>

<br></div><div style><b>FLAC__stream_decoder_init_stream(m_decoder, decoderReadCallback, NULL, NULL, NULL, NULL, decoderWriteCallback, NULL, decoderErrorCallback, input_pile_array);</b><br></div><div style><b><br></b></div>

<div style>Then, callbacks</div><div style><b><br></b></div><div style><div style="font-weight:bold">/// \brief read callback function of decoder</div><div style="font-weight:bold">FLAC__StreamDecoderReadStatus decoderReadCallback(const FLAC__StreamDecoder *decoder, </div>

<div style="font-weight:bold"><span class="" style="white-space:pre">                                                                                                </span>  FLAC__byte buffer[], </div><div style="font-weight:bold"><span class="" style="white-space:pre">                                                                                                </span>  size_t *bytes, </div>

<div style="font-weight:bold"><span class="" style="white-space:pre">                                                                                                </span>  void *callback_param</div><div style="font-weight:bold">);</div><div style="font-weight:bold"><br></div><div style="font-weight:bold">

/// \brief write callback function of decoder</div><div style="font-weight:bold">FLAC__StreamDecoderWriteStatus decoderWriteCallback(const FLAC__StreamDecoder *decoder, </div><div style="font-weight:bold"><span class="" style="white-space:pre">                                                                                                        </span>const FLAC__Frame *frame, </div>

<div style="font-weight:bold"><span class="" style="white-space:pre">                                                                                                        </span>const FLAC__int32 * const buffer[], </div><div style="font-weight:bold"><span class="" style="white-space:pre">                                                                                                        </span>void *callback_param</div>

<div style="font-weight:bold">);</div><div style="font-weight:bold"><br></div><div style="font-weight:bold">/// \brief error callback function of decoder</div><div style="font-weight:bold">void decoderErrorCallback(const FLAC__StreamDecoder *decoder, </div>

<div style="font-weight:bold"><span class="" style="white-space:pre">                                                </span>  FLAC__StreamDecoderErrorStatus status, </div><div style="font-weight:bold"><span class="" style="white-space:pre">                                                </span>  void *callback_param</div>

<div style="font-weight:bold">);</div><div style="font-weight:bold"><br></div><div style>When I call following statement, </div><div style><br></div><div style><div><b>// decode data</b></div><div><b>if(!FLAC__stream_decoder_process_single(m_decoder))</b></div>

<div><b><span class="" style="white-space:pre">        </span>return;</b></div><div><b><br></b></div><div style>firstly, read callback is called. In read callback function, I just use memory copy process.</div><div style><div><br>

</div><div><b>// copy buffer array to m_pile_array</b></div><div><b>if(input_pile_size &gt; 0) {</b></div><div><b><span class="" style="white-space:pre">        </span>memcpy(input_pile_array, buffer, input_pile_size);</b></div>

<div><b><span class="" style="white-space:pre">        </span>input_pile_size = 0;</b></div><div><b><br></b></div><div><b><br></b></div><div><b><span class="" style="white-space:pre">        </span>return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;</b></div>

<div><b>}</b></div><div><b><br></b></div><div><b>return FLAC__STREAM_DECODER_READ_STATUS_ABORT;</b></div><div><b><br></b></div><div style>and I wait for calling write callback but program throws LOST_SYNC exception. I don&#39;t know what causes.</div>

</div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/1 Burak Orçun Özkablan <span dir="ltr">&lt;<a href="mailto:borcunozkablan@gmail.com" target="_blank">borcunozkablan@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Sorry, I am newbie.<div><br></div><div>Sample codes are from <a href="https://github.com/oneman/libflac/tree/master/examples/cpp" target="_blank">https://github.com/oneman/libflac/tree/master/examples/cpp</a>.</div>

<div>
I used <span style="font-size:13px;font-family:arial,sans-serif">FLAC__stream_decoder_process_</span><span style="font-size:13px;font-family:arial,sans-serif">single function but it still gives exception. Maybe I could not control read callback, you&#39;re right.</span></div>


<div><span style="font-size:13px;font-family:arial,sans-serif">I will check it and write result in this thread.</span></div><div><span style="font-size:13px;font-family:arial,sans-serif"><br></span></div><div>
<span style="font-size:13px;font-family:arial,sans-serif">Thanks for help.</span></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/1 Martijn van Beurden <span dir="ltr">&lt;<a href="mailto:mvanb1@gmail.com" target="_blank">mvanb1@gmail.com</a>&gt;</span><br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>I&#39;ll top-post this one because it
      wasn&#39;t sent to the mailinglist but to me. Please reply to list
      next time.<br>
      <br>
      I assume you mean the main.c files in the encode and decode
      directory under examples. I can&#39;t really determine the root cause
      of your problem with this information, but I think you&#39;re trying
      to feed the decoder blocks that are incomplete. The LOST SYNC
      error is usually seen with corrupted blocks, so I think the blocks
      are incomplete or, less likely, corrupt.<br>
      <br>
      There are a few ways to counter this. The easy way is to add a
      little latency to be sure at least one complete block is in the
      receiving buffer. So, only call
      FLAC__stream_decoder_process_single() if the buffer is filled with
      enough data. If you want the lowest latency possible you could
      force a small block size or let the encoding PC signal the
      decoding PC when a block is finished, so the decoding process can
      be sure there is a full block in the buffer.<br>
      <br>
      Oh, and you might take a look at the reading callback, maybe that
      one is overreading the buffer?<br>
      <br>
      I hope that helps.<div><div><br>
      <br>
      On 01-07-13 17:51, Burak Orçun Özkablan wrote:<br>
    </div></div></div><div><div>
    <blockquote type="cite">
      <div dir="ltr">Martijn,
        <div><br>
        </div>
        <div>I encode a one second captured audio data in my PC
          and send it to other PC as encoded. This is OK.</div>
        <div>I want to decode data in other PC and play it but
          when I am decoding data with decoder stream function,
          exception throws.</div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">2013/7/1 Burak Orçun Özkablan <span dir="ltr">&lt;<a href="mailto:borcunozkablan@gmail.com" target="_blank">borcunozkablan@gmail.com</a>&gt;</span><br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">Yes, I mean sample codes in FLAC directory.
              These samples (encode.c and decode.c) are about
              encode/decode with file (using
              FLAC__stream_encoder_init_file and
              FLAC__stream_decoder_init_file functions).
              <div>
                Streaming which I used is audio data transfer over UDP
                or TCP sockets of boost library. </div>
              <div><br>
              </div>
              <div>I send 1 packet which contains 1 second &quot;raw&quot; audio
                data and header information as unsigned char array. In
                the other PC, I play it. I must do it continuously, so I
                said &#39;streaming&#39; for this.</div>
              <div>I can stream without FLAC library but I have to do
                with any codec library because our network bandwidth is
                low so I dont want overhead problem and latency.</div>
              <div><br>
              </div>
              <div>For streaming, FLAC suggests streaming functions such
                as FLAC__stream_encoder_init_stream,
                FLAC__stream_decoder_init_stream. The decoder stream
                function takes 3 callback functions, write, read and
                error.</div>
              <div>What I understand from LOST SYNC exception is write
                and read callback must runs sync. I can not success it,
                code runs only reading callbacks and throws LOST_SYNC
                exception.</div>
            </div>
            <div class="gmail_extra">
              <div>
                <div>
                  <br>
                  <br>
                  <div class="gmail_quote">2013/7/1 Martijn van Beurden
                    <span dir="ltr">&lt;<a href="mailto:mvanb1@gmail.com" target="_blank">mvanb1@gmail.com</a>&gt;</span><br>
                    <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      On 01-07-13 16:48, Burak Orçun Özkablan wrote:<br>
                      &gt; [...]<br>
                      <div>&gt;<br>
                        &gt; I run your sample codes, encode.c and
                        decode.c, about file encode /<br>
                        &gt; decode. Then, I run<br>
                        &gt; streaming encode / decode with two
                        different source codes but when I<br>
                        &gt; use streaming encode / decode over network
                        in real-time, code throws<br>
                        &gt; LOST_SYNC exception and only reading
                        callback runs not writing<br>
                        &gt; callback after exception.<br>
                        <br>
                      </div>
                      I&#39;m not sure I understand what you mean. You are
                      talking about file<br>
                      encode and decode ans streaming encode and decode,
                      do you mean the files<br>
                      in the FLAC source directory example? If so, what
                      is the difference,<br>
                      because I only see file encoding examples?<br>
                      <br>
                      Furthermore, I wonder what you mean by stream. Are
                      you serving a file<br>
                      that is being encoded over HTTP, S(a)MB(a), NFS or
                      something specially<br>
                      designed for streaming, like MMS? So, how are you
                      streaming the FLAC file?<br>
                      <div><br>
                        &gt; How can I solve sync problem over network?
                        Is it possible over network<br>
                        &gt; or does FLAC stream with file?<br>
                        <br>
                      </div>
                      FLAC is capable of streaming, so it should be
                      possible to fix this I guess.<br>
                      _______________________________________________<br>
                      flac-dev mailing list<br>
                      <a href="mailto:flac-dev@xiph.org" target="_blank">flac-dev@xiph.org</a><br>
                      <a href="http://lists.xiph.org/mailman/listinfo/flac-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/flac-dev</a><br>
                    </blockquote>
                  </div>
                  <br>
                  <br clear="all">
                  <div><br>
                  </div>
                </div>
              </div>
              <div>-- <br>
                <div dir="ltr">
                  <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
                    <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
                    </blockquote>
                    <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Burak
                      Orçun ÖZKABLAN</blockquote>
                    <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Computer
                      Science Engineer</blockquote>
                    <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
                    </blockquote>
                    <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Mobile
                       : <a href="tel:0%20541%20302%2018%2078" value="+905413021878" target="_blank">0 541 302
                        18 78</a></blockquote>
                  </blockquote>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div dir="ltr">
          <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
            <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
            </blockquote>
            <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Burak
              Orçun ÖZKABLAN</blockquote>
            <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Computer
              Science Engineer</blockquote>
            <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
            </blockquote>
            <blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Mobile
               : <a href="tel:0%20541%20302%2018%2078" value="+905413021878" target="_blank">0 541 302 18 78</a></blockquote>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br>
  </div></div></div>

<br>_______________________________________________<br>
flac-dev mailing list<br>
<a href="mailto:flac-dev@xiph.org" target="_blank">flac-dev@xiph.org</a><br>
<a href="http://lists.xiph.org/mailman/listinfo/flac-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/flac-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br></blockquote><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


Burak Orçun ÖZKABLAN</blockquote><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Computer Science Engineer</blockquote>


<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br></blockquote><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


Mobile  : <a href="tel:0%20541%20302%2018%2078" value="+905413021878" target="_blank">0 541 302 18 78</a></blockquote></blockquote></div>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br></blockquote><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Burak Orçun ÖZKABLAN</blockquote><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Computer Science Engineer</blockquote>

<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br></blockquote><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Mobile  : 0 541 302 18 78</blockquote></blockquote></div>
</div>