Esempio n. 1
0
static bool_t vorbis_check_fd (const char * filename, VFSFile * file)
{
    ogg_sync_state oy = {0};
    ogg_stream_state os = {0};
    ogg_page og = {0};
    ogg_packet op = {0};

    bool_t result = FALSE;

    ogg_sync_init (& oy);

    while (1)
    {
        int64_t bytes = ogg_sync_pageseek (& oy, & og);

        if (bytes < 0) /* skipped some bytes */
            continue;
        if (bytes > 0) /* got a page */
            break;

        void * buffer = ogg_sync_buffer (& oy, 2048);
        bytes = vfs_fread (buffer, 1, 2048, file);

        if (bytes <= 0)
            goto end;

        ogg_sync_wrote (& oy, bytes);
    }

    if (! ogg_page_bos (& og))
        goto end;

    ogg_stream_init (& os, ogg_page_serialno (& og));
    ogg_stream_pagein (& os, & og);

    if (ogg_stream_packetout (& os, & op) > 0 && vorbis_synthesis_idheader (& op))
        result = TRUE;

end:
    ogg_sync_clear (& oy);
    ogg_stream_clear (& os);

    return result;
}
Esempio n. 2
0
HRESULT Inpin::Start()
{
    m_bEndOfStream = false;
    m_bFlush = false;
    m_bDone = false;

    ogg_packet& pkt = m_packet;

    assert(pkt.packetno < 0);

    if (!bool(m_pPinConnection))
        return S_FALSE;

    const Outpin& outpin = m_pFilter->m_outpin;

    if (!bool(outpin.m_pPinConnection))
        return S_FALSE;

    typedef VorbisTypes::VORBISFORMAT2 FMT;

    const AM_MEDIA_TYPE& mt = m_connection_mtv[0];
    assert(mt.cbFormat > sizeof(FMT));
    assert(mt.pbFormat);

    BYTE* pb = mt.pbFormat;
    BYTE* const pb_end = pb + mt.cbFormat;

    const FMT& fmt = (const FMT&)(*pb);

    pb += sizeof(FMT);
    assert(pb < pb_end);

    const ULONG id_len = fmt.headerSize[0];
    assert(id_len > 0);

    const ULONG comment_len = fmt.headerSize[1];
    assert(comment_len > 0);

    const ULONG setup_len = fmt.headerSize[2];
    assert(setup_len > 0);

    BYTE* const id_buf = pb;
    assert(id_buf < pb_end);

    BYTE* const comment_buf = pb += id_len;
    assert(comment_buf < pb_end);

    BYTE* const setup_buf = pb += comment_len;
    assert(setup_buf < pb_end);

    pb += setup_len;
    assert(pb == pb_end);

    pkt.packet = id_buf;
    pkt.bytes = id_len;
    pkt.b_o_s = 1;
    pkt.e_o_s = 0;
    pkt.granulepos = 0;
    pkt.packetno = 0;

    int status = vorbis_synthesis_idheader(&pkt);
    assert(status == 1);  //TODO

    vorbis_info& info = m_info;
    vorbis_info_init(&info);

    vorbis_comment& comment = m_comment;
    vorbis_comment_init(&comment);

    status = vorbis_synthesis_headerin(&info, &comment, &pkt);
    assert(status == 0);
    assert((info.channels >= 0) && (DWORD(info.channels) == fmt.channels));
    assert((info.rate >= 0) && (DWORD(info.rate) == fmt.samplesPerSec));

    pkt.packet = comment_buf;
    pkt.bytes = comment_len;
    pkt.b_o_s = 0;
    ++pkt.packetno;

    status = vorbis_synthesis_headerin(&info, &comment, &pkt);
    assert(status == 0);

    pkt.packet = setup_buf;
    pkt.bytes = setup_len;
    ++pkt.packetno;

    status = vorbis_synthesis_headerin(&info, &comment, &pkt);
    assert(status == 0);

    status = vorbis_synthesis_init(&m_dsp_state, &info);
    assert(status == 0);

    status = vorbis_block_init(&m_dsp_state, &m_block);
    assert(status == 0);

    m_first_reftime = -1;
    //m_start_reftime
    //m_samples

    m_channels.clear();
    m_channels.resize(fmt.channels);

    assert(m_buffers.empty());

    return S_OK;
}
//---------------------------Start readProperties----------------------------------//
IFACEMETHODIMP VorbisPropertyHandler::readProperties (IStream *pStream) {
   oLOG ("VorbisPropertyHandler::readProperties ()" << std::endl);

   ogg_page         page;
   ogg_sync_state   syncstate;
   ogg_stream_state streamstate;
   ogg_packet       packet;

   int            packetCount = 0;

   // Initialize OGG structures
   V_ASSERT_ (ogg_sync_init (&syncstate) );
   V_ASSERT_ (ogg_stream_init(&streamstate, 0) );

   while (packetCount < 3) {
      H_ASSERT_ (readOGGPacket (pStream, page, syncstate, streamstate, packet) );

      // Check if it is a Vorbis header
      if (packetCount == 0 && vorbis_synthesis_idheader (&packet) != 1)
         break;

      V_ASSERT_ (vorbis_synthesis_headerin (&m_oInfo, &m_oComment, &packet) );

      // A packet is available, this is what we pass to the vorbis or theora libraries to decode.
      packetCount++;
   }

   //vorbis_dsp_state dspstate;
   //vorbis_block block;

   //V_ASSERT_ (vorbis_synthesis_init (&dspstate, &m_oInfo) );
   //V_ASSERT_ (vorbis_block_init (&dspstate, &block) );

#ifdef DEFINE
   g_oLog << "VorbisPropertyHandler::readProperties: m_oInfo = "
      << "\n" << m_oInfo.bitrate_lower
      << "\n" << m_oInfo.bitrate_nominal
      << "\n" << m_oInfo.bitrate_upper
      << "\n" << m_oInfo.bitrate_window
      << "\n" << m_oInfo.channels
      << "\n" << (char*)m_oInfo.codec_setup
      << "\n" << m_oInfo.rate
      << "\n" << m_oInfo.version
      << "\n" << m_oComment.vendor
      << "\n" << m_oComment.comments;

   char buffer[4096];

   for (int i = 0; i < m_oComment.comments; ++i) {
      memcpy (buffer, m_oComment.user_comments[i], m_oComment.comment_lengths[i]);
      buffer[m_oComment.comment_lengths[i] ] = 0;
      g_oLog << "\n" << buffer;
   }

   g_oLog << std::endl;
#endif

   // Delete OGG structures
   V_ASSERT_ (ogg_stream_clear (&streamstate) );
   V_ASSERT_ (ogg_sync_clear (&syncstate) );

   return S_OK;
}//end Fct