#ifndef n_nudpImageSource_H
#define n_nudpImageSource_H

/*
 *
 * nucleo/image/source/nudpImageSource.H --
 *
 * Copyright (C) Nicolas Roussel
 *
 * See the file LICENSE for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include <nucleo/image/source/ImageSource.H>
#include <nucleo/core/URL.H>
#include <nucleo/core/FileKeeper.H>
#include <nucleo/network/udp/UdpReceiver.H>
#include <nucleo/image/encoding/Conversion.H>

namespace nucleo {

  // ------------------------------------------------------------------

  class nudpImageSource : public ImageSource {

  private:

    Image::Encoding _source_encoding ;
    unsigned int _quality ;
    Image::Encoding _target_encoding ;

    std::string _hostOrGroup ;
    int _port ;

    UdpReceiver *_udp ;

    unsigned char *_data ;
    unsigned int _dataSize ;

    enum {CLOSED, OPEN, READY} _state ;

  protected:

    void react(Observable*) ;

  public:

    nudpImageSource(Image::Encoding target_encoding, const URL &url) ;
    ~nudpImageSource() { stop() ; }

    bool start(void) ;
    bool isActive(void) { return _state ; }
    bool getNextImage(Image *img) ;
    bool stop(void) ;

  } ;

  // ------------------------------------------------------------------

}

#endif
